public IActionResult Create() { var model = new ReservationCreateInputModel(); model.StartTime = DateTime.Now; return(this.View(model)); }
public async Task <IActionResult> Create(ReservationCreateInputModel reservationCreateInputModel, string id) { var car = await this.carsService.GetByIdAsync <CarServiceDetailsModel>(id); var currentUser = await this.userManager.GetUserAsync(this.User); reservationCreateInputModel.ClientId = currentUser.Id; reservationCreateInputModel.ParkingId = (int)car.ParkingId; var isCarAvailableByDate = await this.carsService.IsCarAvailableByDate(reservationCreateInputModel.ReservationDate, id); if (!this.ModelState.IsValid || !isCarAvailableByDate) { if (!isCarAvailableByDate) { this.TempData["Error"] = ReservationErrorMessage; } reservationCreateInputModel.Car = car.To <Car>(); reservationCreateInputModel.ClientId = currentUser.Id; reservationCreateInputModel.ParkingId = (int)car.ParkingId; return(this.View(reservationCreateInputModel)); } var reservationServiceModel = reservationCreateInputModel.To <ReservationServiceInputModel>(); await this.reservationsService.CreateAsync(reservationServiceModel); return(this.Redirect("/Reservations/MyReservations")); }
public async Task <JsonResult> Book(int restaurantId, ReservationCreateInputModel reservationCreateInputModel) { var userIdentifier = reservationCreateInputModel.GuestUserEmail ?? this.User.Identity.Name; var reservation = await this.reservationsService.BookAsync(restaurantId, userIdentifier, reservationCreateInputModel); var result = new JsonResult(new { success = 1 }); return(result); }
public async Task <IActionResult> Create() { var model = new ReservationCreateInputModel { Airports = await this.airportsService.GetAllAirportsAsDropdownListAsync() }; return(View(model)); }
public IActionResult Create(ReservationType reservationType, string id, int numberOfTourists) { var inputModel = new ReservationCreateInputModel { ReservationType = reservationType, NumberOfTourists = numberOfTourists, ProductId = id, }; return(this.View(inputModel)); }
public async Task <IActionResult> Create(string id) { var car = await this.carsService.GetByIdAsync <CarServiceDetailsModel>(id); var viewModel = new ReservationCreateInputModel() { CarId = id, Car = car.To <Car>(), }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(ReservationCreateInputModel model) { if (!ModelState.IsValid) { model.StartTime = DateTime.Now; return(this.View(model)); } await reservationService.AddReservation(model); return(RedirectToAction(nameof(RequestSent))); }
public async Task Update(ReservationCreateInputModel model) { var reservation = new Reservation { Id = model.Id, NumberOfSeats = model.NumberOfSeats, Duration = model.Duration, StartTime = model.StartTime, PersonEmail = model.Email, PersonName = model.Name, PersonNumber = model.Number, }; reservationRepository.Update(reservation); await reservationRepository.SaveChangesAsync(); }
public async Task <IActionResult> Create(int roomId, string arrivalDate, string returnDate) { if (!await this.IsValidRoom(DateTime.Parse(arrivalDate), DateTime.Parse(returnDate), roomId)) { return(this.RedirectToAction("Manager")); } var room = await this.roomsService.GetByIdAsync <RoomViewModel>(roomId); var viewModel = new ReservationCreateInputModel { Room = room, ArrivalDate = arrivalDate, ReturnDate = returnDate, }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(ReservationCreateInputModel input) { if (!await this.IsValidRoom(DateTime.Parse(input.ArrivalDate), DateTime.Parse(input.ReturnDate), input.Room.Id)) { return(this.RedirectToAction("Manager")); } if (!this.ModelState.IsValid) { return(this.View(input)); } var userId = this.userManager.GetUserId(this.User); if (input.Room.MaxAdultCount < input.AdultCount || input.AdultCount < 1) { input.AdultCount = null; return(this.View(input)); } if (input.Room.MaxChildCount < input.ChildCount || input.ChildCount < 0) { input.ChildCount = null; return(this.View(input)); } await this.reservationsService.CreateAsync( input.ReservedByGuest.PhoneNumber, userId, input.Room.Id, Convert.ToDateTime(input.ArrivalDate), Convert.ToDateTime(input.ReturnDate), (int)input.AdultCount, (int)input.ChildCount, input.ReservedByGuest.FirstName, input.ReservedByGuest.LastName, input.Description, input.AllPrice, input.HasBreakfast, input.HasLunch, input.HasDinner); return(this.RedirectToAction("Manager", "Reservations")); }
public void AddReservation() { var reservation = new ReservationCreateInputModel { Id = 1, Name = "1", StartTime = DateTime.Now.AddDays(1), Duration = 1, Email = "[email protected]", Number = "08999999999", NumberOfSeats = 2, }; reservationService.AddReservation(reservation); var actual = reservationService.GetReservationById(1); Assert.Equal(reservation.Id, actual.Id); }
public async Task <IActionResult> Create(ReservationCreateInputModel model) { if (model.SourceAirportId == model.DestinationAirportId) { this.ModelState.AddModelError("DestinationAirportId", "Source and destination airports must be different"); } if (!this.ModelState.IsValid) { model.Airports = await this.airportsService.GetAllAirportsAsDropdownListAsync(); var routes = new RoutesInputModel { InboundRoutes = this.reservationsService.GetRoutes(model.SourceAirportId, model.DestinationAirportId), OutboundRoutes = this.reservationsService.GetRoutes(model.SourceAirportId, model.DestinationAirportId) }; this.ViewData["routes"] = routes; return(this.View(model)); } ; return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Create(ReservationCreateInputModel inputModel, string id) { if (!this.ModelState.IsValid) { inputModel.ProductId = id; return(this.View(inputModel)); } var userId = this.userManager.GetUserId(this.User); inputModel.ProductId = id; try { await this.reservationService.CreateAsync(inputModel, userId); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); return(this.View(inputModel)); } return(this.Redirect("/")); }
public async Task <ReservationDetailsViewModel> BookAsync(int restaurantId, string userIdentifier, ReservationCreateInputModel reservationCreateInputModel) { // If identifier is email the user is guest var isGuest = Regex.IsMatch(userIdentifier, ServicesDataConstants.EmailRegex); UnravelTravelUser user = null; if (!isGuest) { user = await this.usersRepository.All().FirstOrDefaultAsync(u => u.UserName == userIdentifier); if (user == null) { throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceUsername, userIdentifier)); } } var restaurant = await this.restaurantsRepository.All().FirstOrDefaultAsync(r => r.Id == restaurantId); if (restaurant == null) { throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceRestaurantId, restaurantId)); } Reservation reservation = null; if (!isGuest) { reservation = await this.reservationsRepository.All() .FirstOrDefaultAsync(r => r.User == user && r.Restaurant == restaurant && r.Date == reservationCreateInputModel.Date); if (reservation != null) { reservation.PeopleCount += reservationCreateInputModel.PeopleCount; this.reservationsRepository.Update(reservation); } } if (reservation == null) { // var utcReservationDate = reservationCreateInputModel.Date.GetUtcDate( // restaurant.Destination.Name, // restaurant.Destination.Country.Name); var utcReservationDate = reservationCreateInputModel.Date.CalculateUtcDateTime(restaurant.Destination.UtcRawOffset); reservation = new Reservation { UserId = user == null ? null : user.Id, Restaurant = restaurant, Date = utcReservationDate, // Save UTC date to Db PeopleCount = reservationCreateInputModel.PeopleCount, }; this.reservationsRepository.Add(reservation); await this.reservationsRepository.SaveChangesAsync(); } var reservationDetailsViewModel = AutoMap.Mapper.Map <ReservationDetailsViewModel>(reservation); var emailContent = await this.GenerateEmailContent(reservationDetailsViewModel); await this.emailSender.SendEmailAsync( user != null?user.Email : userIdentifier, ServicesDataConstants.BookingEmailSubject, emailContent); return(reservationDetailsViewModel); }
public async Task CreateAsync(ReservationCreateInputModel input, string userId) { var reservation = new Reservation { ReservationType = input.ReservationType, Balance = 0, IsAccepted = false, CreatorId = userId, }; double productPrice = 0; if (input.ReservationType.ToString() == "Flight") { var flight = await this.flightRepository.All().FirstOrDefaultAsync(x => x.Id == input.ProductId); if (flight.AvailableSeats != 0) { flight.AvailableSeats--; await this.flightRepository.SaveChangesAsync(); } productPrice = flight.PricePerPerson; reservation.DestinationId = flight.EndPointId; reservation.Departure = flight.DepartureDateTime; reservation.FlightId = input.ProductId; } else if (input.ReservationType.ToString() == "Bus") { var bus = await this.busRepository.All() .FirstOrDefaultAsync(x => x.Id == input.ProductId); if (bus.AvailableSeats != 0) { bus.AvailableSeats--; await this.busRepository.SaveChangesAsync(); } productPrice = bus.PricePerPerson; reservation.DestinationId = bus.EndPointId; reservation.Departure = bus.DepartureDateTime; reservation.BusId = input.ProductId; } else if (input.ReservationType.ToString() == "OrganizedTrip") { var organizedTrip = await this.organizedTripRepository.All() .FirstOrDefaultAsync(x => x.Id == input.ProductId); if (organizedTrip.AvailableSeats != 0) { organizedTrip.AvailableSeats--; await this.organizedTripRepository.SaveChangesAsync(); } productPrice = organizedTrip.PricePerPerson; reservation.DestinationId = organizedTrip.DestinationId; reservation.Departure = organizedTrip.DepartureDateTime; reservation.Return = organizedTrip.ReturnDateTime; reservation.OrganizedTripId = input.ProductId; } else if (input.ReservationType.ToString() == "Hotel") { var hotel = await this.hotelRepository.All() .FirstOrDefaultAsync(x => x.Id.ToString() == input.ProductId); if (hotel.AvailableRooms != 0) { hotel.AvailableRooms--; await this.hotelRepository.SaveChangesAsync(); } productPrice = hotel.PricePerNightPerPerson; reservation.DestinationId = hotel.DestinationId; reservation.HotelId = int.Parse(input.ProductId); reservation.Departure = input.CheckIn + new TimeSpan(14, 00, 00); reservation.Return = input.CheckOut + new TimeSpan(12, 00, 00); productPrice *= (input.CheckOut - input.CheckIn).Days; } foreach (var inputTourist in input.Tourists) { reservation.Tourists.Add(new Tourist { FullName = inputTourist.FullName, DateOfBirth = inputTourist.DateOfBirth, TouristType = inputTourist.TouristType, PersonalNumber = inputTourist.PersonalNumber, PassportNumber = inputTourist.PassportNumber, PhoneNumber = inputTourist.PhoneNumber }); } reservation.Price = productPrice * reservation.Tourists.Count(); reservation.Profit = Math.Round(0.1 * reservation.Price, 2); await this.reservationRepository.AddAsync(reservation); await this.reservationRepository.SaveChangesAsync(); }