public async Task <IActionResult> DetailReservation(string dates, int placeId) { var user = await this.userManager.GetUserAsync(this.User); if (!this.ModelState.IsValid) { return(this.View(dates)); } var place = this.placesService.GetById <PlaceViewModel>(placeId); string[] splitDates = dates.Split(" - "); DateTime startDate = DateTime.Parse(splitDates[0]); DateTime endDate = DateTime.Parse(splitDates[1]); int numNights = (int)(endDate - startDate).TotalDays; double totalPrice = Math.Round(double.Parse(place.PriceByNight) * numNights); var viewModel = new CreateReservationInputModel { PlaceId = placeId, Dates = dates, Place = place, StartDate = startDate, EndDate = endDate, TotalPrice = totalPrice, NumNights = numNights, }; return(this.View(viewModel)); }
public async Task <IActionResult> Index(CreateReservationInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.reservationService.CreateAsync(input); return(this.RedirectToAction(nameof(this.ConfirmedReservation))); }
public async Task <IActionResult> Add(CreateReservationInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var user = await this.userManager.GetUserAsync(this.User); await this.reservationService.AddAsync(user.Id, inputModel.NoOfPeople); return(this.Redirect("/Reservations/Success")); }
public async Task CreateAsync(CreateReservationInputModel input) { var date = input.Date.Date; var time = input.Time.TimeOfDay; var reservationDate = date + time; var reservation = new Reservation { FirstName = input.FirstName, LastName = input.LastName, ReservationDate = reservationDate, Phone = input.Phone, Message = input.Message, }; await this.reservationRepository.AddAsync(reservation); await this.reservationRepository.SaveChangesAsync(); }
public async Task <IActionResult> CreateReservation(CreateReservationInputModel input) { var user = await this.userManager.GetUserAsync(this.User); if (!this.ModelState.IsValid) { return(this.View(input)); } var reservationId = await this.reservationsService.CreateReservationAsync( input.PlaceId, user.Id, input.Dates, input.PriceByNight, input.TotalPrice, input.NumNights); this.TempData["InfoMessage"] = "Reservation created!"; return(this.RedirectToAction(nameof(this.UserReservations))); }