public HttpResponse Add(AddTripInputModel input) { if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("Start point is required.")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("End point is required.")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats should be between 2 and 6.")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Description is required and should be less than 80 characters long.")); } if (!DateTime.TryParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalid data. Please use dd.MM.yyyy HH:mm format.")); } this.tripsService.CreateTrip(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("Start point is required.")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("End point is required.")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats should be between 2 and 6.")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Description is required and has max length of 80.")); } this.tripService.Create(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel model) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(model.StartPoint)) { return(this.Error("StartPoint should be valid!")); } if (string.IsNullOrEmpty(model.EndPoint)) { return(this.Error("EndPoint should be valid!")); } if (!DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalid DepartureTime. Please use dd.MM.yyyy HH:mm format!")); } if (model.Seats < 2 || model.Seats > 6) { return(this.Error("Seats shout be between 2 and 6")); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80) { return(this.Error("Description is required and its length should be at most 80 characters.")); } this.tripsService.AddTrip(model); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel model) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(model.StartPoint)) { return(this.Error("Invalid starting point input.")); } if (string.IsNullOrWhiteSpace(model.EndPoint)) { return(this.Error("Invalid end point input.")); } DateTime validDepartureTime; DateTime.TryParseExact(model.DepartureTime, string.Format("dd.MM.yyyy HH:mm") , CultureInfo.InvariantCulture, DateTimeStyles.None, out validDepartureTime); if (validDepartureTime == null) { return(this.Error("Invalid departure time input.Please input a valid departure time.")); } if (model.Seats < 2 || model.Seats > 6) { return(this.Error("Invalid seats input.Seats must be between 2 and 6.")); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80) { return(this.Error("Invalid description input.Description must be below 80 characters.")); } this.tripsService.AddTrip(model); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { if (string.IsNullOrEmpty(input.StartPoint)) { this.Error("Invalid start point"); } if (string.IsNullOrEmpty(input.EndPoint)) { this.Error("Invalid end point"); } if (input.Seats < 2 || input.Seats > 6) { this.Error("Seats should be between 2 and 6."); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { this.Error("Invalid description"); } if (!DateTime.TryParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalide deaprture time.")); } tripsService.Create(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { // validation this.tripsService.CreateTrip(input); return(this.Redirect("/Trips/All")); }
public void Create(AddTripInputModel trip) { var addTrip = new Trip { StartPoint = trip.StartPoint, EndPoint = trip.EndPoint, DepartureTime = trip.DepartureTime, Description = trip.Description, Seats = trip.Seats, ImagePath = trip.ImagePath, }; this.db.Trips.Add(addTrip); this.db.SaveChanges(); }
public void Create(AddTripInputModel tripModel) { var trip = new Trip() { StartPoint = tripModel.StartPoint, EndPoint = tripModel.EndPoint, DepartureTime = DateTime.ParseExact(tripModel.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Description = tripModel.Description, ImagePath = tripModel.ImagePath, Seats = tripModel.Seats, }; this.dbContext.Trips.Add(trip); this.dbContext.SaveChanges(); }
public void Create(AddTripInputModel input) { var trip = new Trip { StartPoint = input.StartPoint, EndPoint = input.EndPoint, DepartureTime = input.DepartureTime, ImagePath = input.ImagePath, Seats = input.Seats, Description = input.Description, }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void CreateTrip(AddTripInputModel tripModel) { var trip = new Trip() { DepartureTime = DateTime.ParseExact(tripModel.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None), Description = tripModel.Description, EndPoint = tripModel.EndPoint, ImagePath = tripModel.imagePath, Seats = tripModel.Seats, StartPoint = tripModel.StartPoint }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void AddTrip(AddTripInputModel model) { var trip = new Trip() { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DepartureTime = DateTime.ParseExact(model.DepartureTime, string.Format("dd.MM.yyyy HH:mm"), CultureInfo.InvariantCulture), Seats = (byte)model.Seats, Description = model.Description, ImagePath = model.CarImage }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void Create(AddTripInputModel trip) { var dbTrip = new Trip { DepartureTime = DateTime.ParseExact(trip.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Description = trip.Description, EndPoint = trip.EndPoint, ImagePath = trip.ImagePath, Seats = (byte)trip.Seats, StartingPoint = trip.StartPoint, }; this.db.Trips.Add(dbTrip); this.db.SaveChanges(); }
public void Create(AddTripInputModel input) { var trip = new Trip { StartPoint = input.StartPoint, EndPoint = input.EndPoint, Seats = input.Seats, ImagePath = input.ImagePath, Description = input.Description, DepartureTime = DateTime.ParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture) }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void Create(AddTripInputModel model) { var dbTrip = new Trip { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DapartureTime = DateTime.ParseExact(model.DapartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), ImagePath = model.ImagePath, Seats = (byte)model.Seats, Description = model.Description, }; this.db.Trips.Add(dbTrip); this.db.SaveChanges(); }
public string CreateTrip(AddTripInputModel inputModel) { var trip = new Trip { StartPoint = inputModel.StartPoint, EndPoint = inputModel.EndPoint, Description = inputModel.Description, DepartureTime = DateTime.ParseExact(inputModel.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Seats = inputModel.Seats, ImagePath = inputModel.ImagePath }; this.db.Trips.Add(trip); this.db.SaveChanges(); return(trip.Id); }
public HttpResponse Add(AddTripInputModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (String.IsNullOrWhiteSpace(input.StartPoint)) { return(this.Redirect("/Trips/Add")); } if (String.IsNullOrWhiteSpace(input.EndPoint)) { return(this.Redirect("/Trips/Add")); } if (String.IsNullOrWhiteSpace(input.DepartureTime)) { return(this.Redirect("/Trips/Add")); } try { DateTime.ParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture); } catch (Exception) { return(this.Redirect("/Trips/Add")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Redirect("/Trips/Add")); } if (input.Description.Length > 80 || String.IsNullOrWhiteSpace(input.Description)) { return(this.Redirect("/Trips/Add")); } this.tripsService.Create(input.StartPoint, input.EndPoint, input.DepartureTime, input.ImagePath, input.Seats, input.Description); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(input.StartPoint)) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(input.EndPoint)) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(input.DepartureTime) || !DateTime.TryParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Redirect("/Trips/Add")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 80) { return(this.Redirect("/Trips/Add")); } if (!Uri.TryCreate(input.ImagePath, UriKind.Absolute, out _)) { return(this.Redirect("/Trips/Add")); } this.tripsService.AddTrip(input.StartPoint, input.EndPoint, input.ImagePath, input.Seats, input.DepartureTime, input.Description); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel view) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(view.StartPoint) || string.IsNullOrEmpty(view.EndPoint)) { return(this.Error("Startint point and EndPoint must not be empty")); } if (string.IsNullOrEmpty(view.EndPoint)) { return(this.Error("End point is required.")); } if (view.Seats < 2 || view.Seats > 6) { return(this.Error("Seats should be between 2 and 6.")); } if (string.IsNullOrEmpty(view.Description) || view.Description.Length > 80) { return(this.Error("Description is required and has max length of 80.")); } if (!DateTime.TryParseExact( view.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalid departure time. Please use dd.MM.yyyy HH:mm format.")); } this.tripsService.Create(view); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel model) { if (!this.IsUserSignedIn()) { this.Redirect("/Users/Login"); } if (string.IsNullOrEmpty(model.StartPoint)) { return(this.Error("Starting point is required.")); } if (string.IsNullOrEmpty(model.EndPoint)) { return(this.Error("End point is required.")); } if (model.Seats < 2 || model.Seats > 6) { return(this.Error("Seats should be between 2 and 6.")); } if (string.IsNullOrEmpty(model.Description) || model.Description.Length > 80) { return(this.Error("Description is required and has max length of 80 characters.")); } if (!DateTime.TryParseExact( model.DapartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalid departure time.")); } this.tripsService.Create(model); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/")); } if (String.IsNullOrEmpty(model.StartPoint)) { return(this.Redirect("/Trips/Add")); } if (String.IsNullOrEmpty(model.EndPoint)) { return(this.Redirect("/Trips/Add")); } if (String.IsNullOrEmpty(model.DepartureTime)) { return(this.Redirect("/Trips/Add")); } if (!this.tripsService.IsDepartureTimeValid(model.DepartureTime)) { return(this.Redirect("/Trips/Add")); } if (model.Seats < DataConstants.TripMinSeats || model.Seats > DataConstants.TripMaxSeats) { return(this.Redirect("/Trips/Add")); } if (String.IsNullOrEmpty(model.Description) || model.Description.Length > DataConstants.TripDescriptionMaxLenght) { return(this.Redirect("/Trips/Add")); } this.tripsService.Create(model.StartPoint, model.EndPoint, model.DepartureTime, model.ImagePath, model.Seats, model.Description); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("Starting Point is required.")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("End Point is required.")); } if (string.IsNullOrWhiteSpace(input.DepartureTime) || !DateTime.TryParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Departure Time is required in format: dd.MM.yyyy HH:mm")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats should be an integer between 2 and 6.")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Description is required and should be maximum 80 characters long.")); } this.tripsService.AddTrip(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(input.StartPoint)) { return(this.Error("Invalid start point.")); } if (string.IsNullOrWhiteSpace(input.EndPoint)) { return(this.Error("Invalid end point")); } if (string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 80) { return(this.Error("Description is required and has max length of 80 characters.")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats should be between 2 and 6.")); } if (!DateTime.TryParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out _)) { return(this.Error("DateTime should be in format dd.MM.yyyy HH:mm")); } this.tripService.Add(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel tripModel) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(tripModel.StartPoint)) { return(this.Error("Starting point is required!")); } if (string.IsNullOrEmpty(tripModel.EndPoint)) { return(this.Error("End point is required!")); } if (tripModel.Seats < 2 || tripModel.Seats > 6) { return(this.Error("Seats must be between 2 and 6!")); } if (string.IsNullOrEmpty(tripModel.Description) || tripModel.Description.Length > 80) { return(this.Error("Description must be below 80 characters!")); } if (!DateTime .TryParseExact(tripModel.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalid date!")); } ; this.tripService.CreateTrip(tripModel); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel input) { if (!IsUserSignedIn()) { return(this.Redirect("/")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("Start point is required.")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("End point is required.")); } if (string.IsNullOrEmpty(input.DepartureTime.ToString("dd.MM.yyyy HH:mm"))) { return(this.Error("Invalid departure time.")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats shoud be between 2 and 6.")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Descripiton is required and should be up to 80 characters long.")); } this.tripsService.Create(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(AddTripInputModel model) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(model.StartPoint)) { return(this.Error("Invalid start point")); } if (string.IsNullOrEmpty(model.EndPoint)) { return(this.Error("Invalid end point")); } if (model.Seats < 2 && model.Seats > 6) { return(this.Error("Seats should be between 2 and 6")); } if (string.IsNullOrEmpty(model.Description) || model.Description.Length > 80) { return(this.Error("Description is required and must by max 80 characters length")); } if (!DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Departure time must be in dd.MM.yyyy HH:mm format")); } this.tipsServices.Create(model); return(this.Redirect("/Trips/All")); }