public void CreateTrip(TripDetailsInputViewModel detailsInputView) { var tripToAdd = new Trip { StartPoint = detailsInputView.StartPoint, EndPoint = detailsInputView.EndPoint, DepartureTime = DateTime.ParseExact(detailsInputView.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Seats = detailsInputView.Seats, Description = detailsInputView.Description, ImagePath = detailsInputView.ImagePath }; this.db.Trips.Add(tripToAdd); this.db.SaveChanges(); }
public HttpResponse Add(TripDetailsInputViewModel detailsInputView) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(detailsInputView.StartPoint)) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(detailsInputView.EndPoint)) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(detailsInputView.DepartureTime)) { return(this.Redirect("/Trips/Add")); } if (detailsInputView.Seats < 2 || detailsInputView.Seats > 6) { return(this.Redirect("/Trips/Add")); } if (string.IsNullOrWhiteSpace(detailsInputView.Description)) { return(this.Redirect("/Trips/Add")); } this.tripsService.CreateTrip(detailsInputView); return(this.Redirect("/Trips/All")); }