public HttpResponse Add(TripInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(input.StartPoint)) { return(this.Error("Start point required!")); } if (string.IsNullOrEmpty(input.EndPoint)) { return(this.Error("End point required!")); } if (string.IsNullOrEmpty(input.DepartureTime) || !DateTime.TryParse(input.DepartureTime, out _)) { return(this.Error("Departure time required!")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats should be between 2 and 6!")); } if (string.IsNullOrEmpty(input.Description)) { return(this.Error("Description required!")); } this.tripsService.Create(input); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripInputModel input) { if (!this.IsUserSignedIn()) { return(this.Redirect("/users/login")); } if (string.IsNullOrWhiteSpace(input.StartPoint)) { return(this.Error("You should choose any start point")); } if (string.IsNullOrWhiteSpace(input.EndPoint)) { return(this.Error("You should choose any end point")); } if (input.Seats < 2 || input.Seats > 6) { return(this.Error("Seats must have value between 2 and 6.")); } if (string.IsNullOrWhiteSpace(input.Description) || input.Description.Length > 80) { return(this.Error("Description is required and should be less than 80 charackters long")); } if (!Uri.IsWellFormedUriString(input.ImagePath, UriKind.Absolute)) { return(this.Error("Please fill valid image url")); } if (!Regex.IsMatch(input.DepartureTime, @"^\d{2}\.\d{2}\.\d{4} \d{2}\:\d{2}$")) { return(this.Error("Departure time format is not correct")); } this.tripsService.CreateTrip(input); return(this.Redirect("/Trips/All")); }
public IActionResult Create(TripInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } this.TempData["id"] = this._tripsService.Create(model); return(this.RedirectToAction("Details")); }
public void Add(TripInputModel tripInput) { var trip = new Trip() { StartPoint = tripInput.StartPoint, EndPoint = tripInput.EndPoint, Description = tripInput.Description, DepartureTime = DateTime.Parse(tripInput.DepartureTime).ToUniversalTime(), ImagePath = tripInput.ImagePath, Seats = int.Parse(tripInput.Seats), }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public string Create(TripInputModel model) { var trip = new Trip { Name = model.Name, Description = model.Description, Duration = model.Duration, MapUrl = model.MapUrl, }; this._tripRepository.AddAsync(trip); this._tripRepository.SaveChangesAsync(); return(trip.Id); }
public void Create(TripInputModel model) { var trip = new Trip { StartPoint = model.StartPoint, EndPoint = model.EndPoint, DepartureTime = DateTime.Parse(model.DepartureTime), ImagePath = model.ImagePath, Seats = model.Seats, Description = model.Description }; this.db.Trips.Add(trip); this.db.SaveChanges(); }
public void Create(TripInputModel tripvm) { var trip = new Trip { StartPoint = tripvm.StartPoint, Seats = tripvm.Seats, EndPoint = tripvm.EndPoint, DepartureTime = DateTime.ParseExact(tripvm.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Description = tripvm.Description, ImagePath = tripvm.ImagePath, }; this.context.Trips.Add(trip); this.context.SaveChanges(); }
public string CreateTrip(TripInputModel input) { var trip = new Trip { Seats = input.Seats, StartPoint = input.StartPoint, DepartureTime = DateTime.ParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), Description = input.Description, EndPoint = input.EndPoint, ImagePath = input.ImagePath }; this.db.Trips.Add(trip); db.SaveChanges(); return(trip.Id); }
public async Task <IActionResult> Post(TripInputModel tripInput) { var response = new Response(); var existsCity = this.citiesService.Exists(x => x.Id == tripInput.CityId); var existsCrag = this.cragsService.Exists(x => x.Id == tripInput.CragId); var existsSector = this.sectorsService.Exists(x => x.Id == tripInput.SectorId && x.CragId == tripInput.CragId); if (tripInput.SectorId == null) { existsSector = true; } if (!this.ModelState.IsValid || tripInput.Leaving > tripInput.Returning) { return(this.BadRequest("Invalid input!")); } if (!existsCity) { response.Message = "No such city!"; return(this.NotFound(response)); } if (!existsCrag) { response.Message = "No such crag!"; return(this.NotFound(response)); } if (!existsSector) { response.Message = "No such sector!"; return(this.NotFound(response)); } tripInput.ApplicationUserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await this.tripsService.AddAsync(tripInput); response.Message = "Successfully created trip"; return(this.Ok(response)); }
public HttpResponse Details(string tripId) { if (!this.IsUserSignedIn()) { return(this.Redirect("/users/login")); } var trip = this.tripsService.GetTripById(tripId); var specialDate = trip.DepartureTime.ToString("s"); var freeSeats = trip.Seats - this.userTripService.GetCountOfTripOcupiedSeats(trip.Id); var tripViewModel = new TripInputModel() { Seats = freeSeats, StartPoint = trip.StartPoint, DepartureTime = specialDate, Description = trip.Description, EndPoint = trip.EndPoint, ImagePath = trip.ImagePath, Id = trip.Id }; return(this.View(tripViewModel)); }
public HttpResponse Add(TripInputModel tripInput) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrWhiteSpace(tripInput.StartPoint) || string.IsNullOrWhiteSpace(tripInput.EndPoint) || string.IsNullOrWhiteSpace(tripInput.DepartureTime) || string.IsNullOrWhiteSpace(tripInput.Description) || string.IsNullOrWhiteSpace(tripInput.Seats)) { return(this.View()); } var pattern = @"^([1-9]|([012][0-9])|(3[01])).([0]{0,1}[1-9]|1[012]).\d\d\d\d [012]{0,1}[0-9]:[0-6][0-9]$"; var match = Regex.Match(tripInput.DepartureTime, pattern); if (!match.Success) { return(this.View()); } if (int.Parse(tripInput.Seats) < 2 || int.Parse(tripInput.Seats) > 6) { return(this.View()); } if (tripInput.Description.Length > 80) { return(this.View()); } this.tripsService.Add(tripInput); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripInputModel model) { if (!this.IsUserSignedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(model.StartPoint)) { return(this.Error("Start point is required")); } if (string.IsNullOrEmpty(model.EndPoint)) { return(this.Error("End point is required")); } DateTime date; if (!DateTime.TryParseExact(model.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { return(this.Error("Departure time should be in \"dd.MM.yyyy HH: mm\" format.")); } if (model.Seats < 2 || model.Seats > 6) { return(this.Error("Sears should be between 2 and 6.")); } if (string.IsNullOrEmpty(model.Description) || model.Description.Length > 80) { return(this.Error("Description is required and should be below 80 characters.")); } this.tripsService.Add(model.StartPoint, model.EndPoint, date, model.ImagePath, model.Seats, model.Description); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripInputModel inputModel) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/Users/Login")); } if (string.IsNullOrEmpty(inputModel.StartPoint) || string.IsNullOrEmpty(inputModel.EndPoint) || string.IsNullOrEmpty(inputModel.DepartureTime) || string.IsNullOrEmpty(inputModel.DepartureTime)) { return(this.Redirect("/Trips/Add")); } //if(DateTime.TryParse(inputModel.DepartureTime, out DateTime departureTime)) if (!DateTime.TryParseExact(inputModel.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime departureTime)) { return(this.Redirect("/Trips/Add")); } if (inputModel.Seats < 2 || inputModel.Seats > 6) { return(this.Redirect("/Trips/Add")); } if (inputModel.Description.Length > 80) { return(this.Redirect("/Trips/Add")); } this.tripsService.Add(inputModel.StartPoint, inputModel.EndPoint, departureTime, inputModel.Seats, inputModel.Description, inputModel.ImagePath); return(this.Redirect("/Trips/All")); }
public HttpResponse Add(TripInputModel 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 must be between 2 and 6")); } if (string.IsNullOrEmpty(input.Description) || input.Description.Length > 80) { return(this.Error("Description must be shorter than 80")); } if (!DateTime.TryParseExact(input.DepartureTime, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)) { return(this.Error("Invalid Date")); } this.tripsService.Create(input); return(this.Redirect("/Trips/All")); }