public HttpResponse Add(TripsInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("A starting point is required.")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("An ending point is required.")); } if (string.IsNullOrEmpty(input.DepartureTime)) { return(this.Error("A Departure time is required.")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats count should be between 2 and 6.")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Description should be 80 characters long.")); } this.tripsService.CreateTrip(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripsInputModel input) { tripsService.AddTrip(input); if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } return(this.Redirect("Trips/All")); }
public void Add(TripsInputModel model) { var trip = new Trip() { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DepartureTime = DateTime.ParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), ImagePath = model.ImagePath, Seats = model.Seats, Description = model.Description }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void Add(TripsInputModel inputModel) { var trip = new Trip() { StartPoint = inputModel.StartPoint, EndPoint = inputModel.EndPoint, DepartureTime = inputModel.DepartureTime, Seats = inputModel.Seats, Description = inputModel.Description, ImagePath = inputModel.ImagePath, }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void CreateTrip(TripsInputModel input) { var trip = new Trip { StartPoint = input.StartPoint, EndPoint = input.EndPoint, DepartureTime = DateTime.ParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), ImagePath = input.ImagePath, Seats = input.Seats, Description = input.Description, }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public HttpResponse Add(TripsInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(inputModel.Description) || inputModel.Description.Length > 80) { return(this.View()); } this.tripsService.Add(inputModel); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripsInputModel model) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(model.Description) || model.Description.Length > 80) { return(this.Redirect("/Trips/Add")); } if (model.Seats > 6 || model.Seats < 2) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrEmpty(model.EndPoint)) { return(this.Redirect("/Trips/Add")); } if (model.DepartureTime == null) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrEmpty(model.StartPoint)) { return(this.Redirect("/Trips/Add")); } var trip = new Trip { DepartureTime = DateTime.ParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Description = model.Description, EndPoint = model.EndPoint, ImagePath = model.ImagePath, Seats = model.Seats, StartPoint = model.StartPoint, }; this.service.AddTrip(trip); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripsInputModel model) { if (!User.IsAuthenticated) { //return Redirect("/Users/Login"); return(Error($"401 Unauthorized")); // This way is more ser-friendly } bool isParsed = DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _); var userId = User.Id; if (string.IsNullOrWhiteSpace(model.StartPoint)) { //return Redirect("/Trips/Add"); return(Error("Start point is required")); // This way is more ser-friendly } if (string.IsNullOrWhiteSpace(model.EndPoint)) { //return Redirect("/Trips/Add"); return(Error("End point is required")); } if (2 > model.Seats || model.Seats > 6) { //return Redirect("/Trips/Add"); return(Error("Seat should be between 2 and 6")); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80) { //return Redirect("/Trips/Add"); return(Error("Description is required and has max length of 80")); } if (!isParsed) { //return Redirect("/Trips/Add"); return(Error("Invalid Departure time. Please use this format (dd.MM.yyyy HH: mm)")); } tripsService.Add(model, userId); return(Redirect("/")); }
public string AddTrip(TripsInputModel tripsInputModel) { var trip = new Trip() { StartPoint = tripsInputModel.StartPoint, EndPoint = tripsInputModel.EndPoint, DepartureTime = tripsInputModel.DepartureTime, Description = tripsInputModel.Description, Seats = tripsInputModel.Seats, ImagePath = tripsInputModel.ImagePath, }; this.dbContext.Trips.Add(trip); this.dbContext.SaveChanges(); return(trip.Id); }
public void Add(TripsInputModel model, string userId) { db.UserTrips.Add(new UserTrip { UserId = userId, Trip = new Trip { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DepartureTime = DateTime.ParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), ImagePath = model.ImagePath, Seats = model.Seats, Description = model.Description, } }); db.SaveChanges(); }
public HttpResponse Add(TripsInputModel model) { if (!IsUserSignIn()) { return(Redirect("/")); } bool isParsed = DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _); var userId = GetUserId(); if (string.IsNullOrWhiteSpace(model.StartPoint)) { return(Error("Start point is required")); } if (string.IsNullOrWhiteSpace(model.EndPoint)) { return(Error("End point is required")); } if (2 > model.Seats || model.Seats > 6) { return(Error("Seat should be between 2 and 6")); } if (string.IsNullOrWhiteSpace(model.Description) || model.Description.Length > 80) { return(Error("Description is required and has max length of 80")); } if (!isParsed) { return(Error("Invalid Departure time. Please use this format (dd.MM.yyyy HH: mm)")); } tripsService.Add(model, userId); return(Redirect("/Trips/All")); }
public HttpResponse Add(TripsInputModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.View()); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.View()); } if (string.IsNullOrEmpty(input.DepartureTime)) { return(this.View()); } if (input.Seats < 2 || input.Seats > 6) { return(this.View()); } if (input.Description.Length > 80) { return(this.View()); } this.tripsService.Add(input); return(this.Redirect("/Trips/All")); }