public async Task <IActionResult> ByName(ReservationInputModel model) { string username = this.User.Identity.Name; if (!this.ModelState.IsValid) { return(this.PartialView("~/Views/ServiceTypes/_ReservationModalForm.cshtml", model)); } var reservation = new CreateReservationServiceModel { VehicleMake = model.VehicleMake, VehicleModel = model.VehicleModel, LicenseNumber = model.LicenseNumber, ReservationDateTime = DateTime.ParseExact(model.ReservationDateTime, "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture), PhoneNumber = model.PhoneNumber, ServiceId = model.ServiceId, OperatingLocationId = model.OperatingLocationId, Username = username, }; await this.reservationsService.CreateAsync(reservation); if (this.User.IsInRole("User")) { return(this.RedirectToAction("MyReservations", "Reservations")); } return(this.RedirectToAction("ByName")); }
public async Task <IActionResult> Create(ReservationInputModel model) { int ecenomyTickets = model.Passengers.Count(p => p.TicketType == TicketType.Economy); int bussinesTickets = model.Passengers.Count(p => p.TicketType == TicketType.Bussines); int availableEconomyTickets = flightService.AvailableEconomyTickets(model.FlightId); int availableBusinessTickets = flightService.AvailableBussinesTickets(model.FlightId); if (availableEconomyTickets < ecenomyTickets) { ModelState.AddModelError(string.Empty, $"There are only {availableEconomyTickets} economy tickets left."); } if (availableBusinessTickets < bussinesTickets) { ModelState.AddModelError(string.Empty, $"There are only {availableBusinessTickets} business tickets left."); } if (!ModelState.IsValid) { return(View(model)); } await reservationService.Create(model); await flightService.UpdateAvailableTickets(model.FlightId, ecenomyTickets, bussinesTickets); FlightViewModel flight = flightService.GetById <FlightViewModel>(model.FlightId); await SendConfirmationEmailsToPassengers(model.Passengers, flight); await SendEmailToClient(model.Client.Email, flight, model.Passengers); return(Redirect("/")); }
public async Task CreateReservation(ReservationInputModel input) { var flight = await this.db.Flights.FirstOrDefaultAsync(f => f.Id == input.FlightId); if (flight == null) { throw new ArgumentException("Invalid flight!"); } var reservation = new ReservationDataModel() { FirstName = input.FirstName, MiddleName = input.MiddleName, LastName = input.LastName, EGN = input.EGN, Nationality = input.Nationality, TelNumber = input.TelNumber, TicketType = input.TicketType, Flight = flight, FlightId = flight.Id, }; flight.Reservations.Add(reservation); await this.db.Reservations.AddAsync(reservation); await this.db.SaveChangesAsync(); }
public IActionResult Create(int flightId) { var reservation = new ReservationInputModel(); reservation.Passengers.Add(new ReservationPassangerInputModel()); reservation.FlightId = flightId; return(View(reservation)); }
// GET: ReservationDataModels/Create public IActionResult Create(string flightId) { var model = new ReservationInputModel() { FlightId = flightId, }; return(View(model)); }
public async Task <IActionResult> Create(ReservationInputModel model) { if (ModelState.IsValid) { await this.reservationsService.CreateReservation(model); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(ReservationInputModel inputModel) { var model = this.reservationsService.ParseData(inputModel.Price, inputModel.SelectedSeats); var userId = this.userManager.GetUserId(this.User); var reservationId = await this.reservationsService.AddAsync(model.SelectedSeats, model.Price, inputModel.ProjectionId, userId); this.TempData["seatIds"] = model.SelectedSeatsIds.ToList(); return(this.RedirectToAction("GetById", new { reservationId })); }
public IActionResult CreateNewReservation(ReservationInputModel model) { if (model.CheckIn.Date >= model.CheckOut.Date || model.CheckIn.Date < DateTime.Now.Date) { HttpContext.Session.SetString("Message", "Please enter valid CheckIn and CheckOut Dates"); return(RedirectToAction(nameof(Index))); } if ((model.Adults <= 0 && model.Children <= 0) || model.Adults < 0 || model.Children < 0) { HttpContext.Session.SetString("Message", "Please check Room capacity for Adults and Children."); return(RedirectToAction(nameof(Index))); } var season = _seasonRepository.GetSeasonByDate(DateTime.Now); var room = _roomRepository.GetRoomById(model.RoomId); var meal = _mealRepository.GetMealById(model.MealId); var roomRateBySeasonIdAndRoomId = _roomRateRepository.GetRoomRateBySeasonIdAndRoomId(season.Id, model.RoomId); var mealRateBySeasonIdAndRoomId = _mealRateRepository.GetMealRateBySeasonIdAndRoomId(season.Id, model.MealId); var numOfRoomsForAdults = model.Adults / room.MaxNumOfAdults + (model.Adults % room.MaxNumOfAdults > 0 ? 1 : 0); var numOfRoomsForChildren = model.Children / room.MaxNumOfChildren + (model.Children % room.MaxNumOfChildren > 0 ? 1 : 0); var numOfRooms = numOfRoomsForAdults > numOfRoomsForChildren ? numOfRoomsForAdults : numOfRoomsForChildren; var numOfDays = model.CheckOut.Subtract(model.CheckIn).Days; var total = _reservationRepository.CalculateReservationCost(numOfRooms, numOfDays, model.Adults + model.Children, roomRateBySeasonIdAndRoomId.Price, mealRateBySeasonIdAndRoomId.Price); var reservation = Reservation.New(model.Name, model.Email, model.Country, model.Adults, model.Children, room, meal, season, model.CheckIn, model.CheckOut, total); _reservationRepository.SaveReservation(reservation); total = decimal.Round(total, 4); ViewBag.Total = total; return(View("SuccessReservation", model)); }
private async Task<ReservationInputModel> FillRoomData(ReservationInputModel inputModel, RoomViewModel room) { inputModel.RoomId = room.Id; inputModel.Reservations = room.Reservations.AsQueryable().ProjectTo<ReservationPeriod>().ToList(); inputModel.RoomCapacity = room.Capacity; inputModel.AllInclusivePrice = await memoryCache.GetAllInclusivePrice(settingService); inputModel.RoomAdultPrice = room.AdultPrice; inputModel.BreakfastPrice = await memoryCache.GetBreakfastPrice(settingService); inputModel.RoomChildrenPrice = room.ChildrenPrice; inputModel.RoomType = room.Type; inputModel.RoomImageUrl = room.ImageUrl; return inputModel; }
public async Task<IActionResult> Create(string id, ReservationInputModel inputModel) { var room = await roomService.GetRoom<RoomViewModel>(id); if (room == null || (room?.IsTaken ?? true)) { return this.NotFound(); } var roomIsEmpty = await reservationService.AreDatesAcceptable(room.Id, inputModel.AccommodationDate, inputModel.ReleaseDate); if (!roomIsEmpty) { this.ModelState.AddModelError(nameof(inputModel.AccommodationDate), "Room is already reserved at that time"); } if (!this.ModelState.IsValid) { return this.View(await FillRoomData(inputModel, room)); } var clients = new List<ClientData>(); foreach (var client in inputModel.Clients) { clients.Add(await this.userService.CreateClient(client.Email, client.FullName, client.IsAdult)); } var user = await userManager.GetUserAsync(User); var reservation = await reservationService.AddReservation( room.Id, inputModel.AccommodationDate, inputModel.ReleaseDate, inputModel.AllInclusive, inputModel.Breakfast, clients, user); return this.RedirectToAction(nameof(Details), new { id = reservation.Id }); }
public async Task Create(ReservationInputModel model) { Reservation reservation = model.To <Reservation>(); Client client = GetReservationClient(model.Client.Email); //Check if client has already been added to the database if (client != null) { reservation.Client = client; } foreach (ReservationPassangerInputModel passanger in model.Passengers) { reservation.Passengers.Add(GetReservationPassanger(passanger)); } await context.Reservations.AddAsync(reservation); await context.SaveChangesAsync(); }
public async Task<IActionResult> Update(string id, ReservationInputModel inputModel) { var user = await userManager.GetUserAsync(User); var reservation = await reservationService.GetReservation<ReservationInputModel>(id); if (reservation == null || !(user.Id == reservation.UserId || User.IsInRole("Admin")) || reservation.ReleaseDate < DateTime.Today) { return this.NotFound(); } var room = await roomService.GetRoom<RoomViewModel>(reservation.RoomId); reservation = await FillRoomData(reservation, room); if (reservation.Reservations?.Any() ?? false) { reservation.Reservations = reservation.Reservations. Where(x => !(x.AccommodationDate == reservation.AccommodationDate && x.ReleaseDate == reservation.ReleaseDate)); } var roomIsEmpty = await reservationService.AreDatesAcceptable(room.Id, inputModel.AccommodationDate, inputModel. ReleaseDate,id); if (!roomIsEmpty) { this.ModelState.AddModelError(nameof(inputModel.AccommodationDate), "Room is already reserved at that time"); } if (!this.ModelState.IsValid) { inputModel = await FillRoomData(inputModel, room); return this.View(inputModel); } var cls = inputModel.Clients.Select(x => new ClientData { IsAdult = x.IsAdult, Email = x.Email, FullName = x.FullName, Id = x.Id, }).ToList(); var clients = await reservationService.UpdateClientsForReservation(reservation.Id, cls); var success = await reservationService.UpdateReservation( reservation.Id, inputModel.AccommodationDate, inputModel.ReleaseDate, inputModel.AllInclusive, inputModel.Breakfast, clients, user); if (!success) { ModelState.AddModelError("", "Error updating reservation"); inputModel = await FillRoomData(inputModel, room); return this.View(inputModel); } return this.RedirectToAction(nameof(Details), new { id = reservation.Id }); }