Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-prakash-tiwari committed Feb 25, 2020
1 parent dcbaa84 commit c3a2218
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CarPooling.Models/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class Constant

public static readonly string ConfirmOption = "Press 1 for confirm this offer";

public static readonly string Another = "Press 1. Yes\n 2. No";

public static readonly string UpdateDetailResponse = "Your detail has been updated";

public static readonly string AccountDeleteResponse = "You account has been deleted";
Expand Down Expand Up @@ -99,5 +101,9 @@ public class Constant
public static readonly string DisplayWaitingBooking = "Waiting for owner response";

public static readonly string NoOfViaPlaces = "No of via place : ";

public static readonly string UserNameAvailable = "Sorry this username will be taken by someone please choose another or username will be null";

public static readonly string ViaCities = "Via City";
}
}
5 changes: 5 additions & 0 deletions CarPooling.Services/AppDataServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ public static Booking GetBooking(Guid id)
{
return Users.SelectMany(a => a.Bookings).FirstOrDefault(a => a.Id == id);
}

public static bool GetUserNameAvailabilty(string Id)
{
return Users.Select(a => a.Id).Contains(Id);
}
}
}
5 changes: 5 additions & 0 deletions CarPooling/DisplayData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public static void OfferRide(Ride ride)
Console.WriteLine(Constant.CarCapacity + ride.Car.MaxSeatCapacity);
Console.WriteLine(Constant.JourneyDetail);
Console.WriteLine(Constant.Source + ride.SourceCityName);
Console.WriteLine(Constant.ViaCities+ " : "+ ride.Points.Count);
foreach (var city in ride.Points)
{
Console.WriteLine(Constant.City + city.City);
}
Console.WriteLine(Constant.Destination + ride.DestinationCityName);
Console.WriteLine(Constant.Date + ride.Date);
Console.WriteLine(Constant.Pincode + ride.Pincode);
Expand Down
27 changes: 27 additions & 0 deletions CarPooling/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace CarPooling
Expand Down Expand Up @@ -44,6 +45,32 @@ public static DateTime ValidDate()
return date;
}

public static string GetValidEmail()
{
string email = Console.ReadLine();
Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
Match match = regex.Match(email);
if (string.IsNullOrEmpty(email) || !match.Success)
{
Console.WriteLine(Constant.InvalidValue);
email = GetValidEmail();
}

return email;
}

public static string GetValidUserName()
{
string userName = Console.ReadLine();
if (string.IsNullOrEmpty(userName) || (!AppDataServices.GetUserNameAvailabilty(userName)))
{
Console.WriteLine(Constant.UserNameAvailable);
userName = GetValidUserName();
}

return userName;
}

public static string GetValidCity()
{
string cityName = Console.ReadLine();
Expand Down
10 changes: 9 additions & 1 deletion CarPooling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,18 @@ public void UserMainMenu()
{
Console.WriteLine(Constant.SeatBookResponse);
}

break;

case BookingStatus.Rejected:
this.BookingServices.SeatBookingReject(bookingId);

break;
}
if (UserInput.Confirmation() == ConfirmationResponse.Yes)
{
break;
}

}

if (rides.Count < 1)
Expand Down Expand Up @@ -184,6 +188,10 @@ public void UserMainMenu()

break;
}
if (UserInput.Confirmation() == ConfirmationResponse.Yes)
{
break;
}
}
Console.ReadKey();
UserMainMenu();
Expand Down
26 changes: 24 additions & 2 deletions CarPooling/UserInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static User NewUser()
User user = new User();

Console.Write(Constant.UserId);
user.Id = Helper.ValidString();
user.Id = Helper.GetValidUserName();

Console.Write(Constant.Password);
user.Password = Helper.ValidString();
Expand All @@ -28,7 +28,7 @@ public static User NewUser()
user.MobileNumber = Helper.ValidString();

Console.Write(Constant.Email);
user.Email = Helper.ValidString();
user.Email = Helper.GetValidEmail();

Console.Write(Constant.Address);
user.Address = Helper.ValidString();
Expand Down Expand Up @@ -191,6 +191,28 @@ public static ConfirmationResponse Confirmation()
}
}

public static ConfirmationResponse Response()
{
Console.WriteLine(Constant.Another);

ConfirmationResponse option = (ConfirmationResponse)Helper.ValidInteger();

switch (option)
{
case ConfirmationResponse.Yes:
return ConfirmationResponse.Yes;

case ConfirmationResponse.No:
return ConfirmationResponse.No;

default:
Console.WriteLine(Constant.InvalidValue);
option = Confirmation();
return option;

}
}

public static BookingStatus BookingChoice()
{
Console.WriteLine(Constant.RideRequestChoice);
Expand Down

0 comments on commit c3a2218

Please sign in to comment.