Exemplo n.º 1
0
        public IActionResult Create(ReservationCreateViewModel model)
        {
            Flight flight = flightService.GetFlightById(model.FlightId);

            if (model.TicketType == "Business" && flight.BusinessTicketsLeft < model.TicketCount)
            {
                model.ErrorMessage = "Not enough Business class tickets!";
                return(View("Create", model));
            }
            else if (model.TicketType == "Regular" && flight.TicketsLeft < model.TicketCount)
            {
                model.ErrorMessage = "Not enough Regular class tickets!";
                return(View("Create", model));
            }

            ReservationCreateViewModel resModel = new ReservationCreateViewModel()
            {
                Email               = model.Email,
                FirstName           = model.FirstName,
                SecondName          = model.SecondName,
                LastName            = model.LastName,
                SSN                 = model.SSN,
                PhoneNumber         = model.PhoneNumber,
                Nationality         = model.Nationality,
                TicketType          = model.TicketType,
                TicketCount         = model.TicketCount,
                BusinessTicketsLeft = flight.BusinessTicketsLeft,
                FlightId            = flight.FlightID,
                TicketsLeft         = flight.TicketsLeft
            };

            reservationService.CreateReservation(resModel);

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(ReservationCreateViewModel model)
        {
            var userId = _userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                var parking     = _context.Parkings.FirstOrDefault(f => f.Id == model.ParkingId);
                var totalAmount = model.ParkingDuration * parking.PricePerHour;
                if (_walletService.Pay(totalAmount, User))
                {
                    var parkingReservation = new ParkingReservation
                    {
                        UserId           = userId,
                        CarCategory      = model.CarCategory,
                        CarNumber        = model.CarNumber,
                        ParkingDate      = model.ParkingDate,
                        ParkingTime      = model.ParkingDuration,
                        VerificationCode = Guid.NewGuid(),
                        AmountPaid       = model.ParkingDuration * parking.PricePerHour,
                        SlotNumber       = model.SlotNumber,
                        ParkingId        = model.ParkingId
                    };
                    _context.Add(parkingReservation);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), "Reservations", new { id = parkingReservation.Id }));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Resurse insuficiente în cont.");
                }
            }
            model.AvailableParkings = _context.Parkings.ToList();
            return(View(model));
        }
Exemplo n.º 3
0
        // GET: Reservation/Create
        public IActionResult Create()
        {
            ReservationCreateViewModel model = new ReservationCreateViewModel();

            List <ReservationCreateClientViewModel> clients = _context.Clients
                                                              .Select(x => new ReservationCreateClientViewModel(x.Id, x.Name))
                                                              .ToList();

            List <ReservationCreateRoomViewModel> rooms = _context.Rooms.Select(x => new ReservationCreateRoomViewModel(x.Id, x.RoomType, x.PricePerAdult, x.PricePerChild, x.IsFree)).ToList();
            //rooms = rooms.Where(r => r.IsFree = true).ToList();

            List <ReservationCreateRoomViewModel> freeRooms = new List <ReservationCreateRoomViewModel>();

            foreach (var room in rooms)
            {
                if (room.IsFree)
                {
                    freeRooms.Add(room);
                }
            }

            model.CreateClient = clients;
            model.RoomsAdded   = freeRooms;

            return(View(model));
        }
Exemplo n.º 4
0
        public ReservationCreateView(ReservationModel reservation)
        {
            InitializeComponent();
            ReservationCreateViewModel binding = new ReservationCreateViewModel(this, reservation);

            BindingContext = binding;

            binding.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "IdUser" && binding.IdUser != -1)
                {
                    entMail.IsEnabled = entPhone.IsEnabled = false;
                }
            };

            sbName.TextChanged += (s, e) =>
            {
                if (sbName.Text == string.Empty)
                {
                    binding.Name      = binding.Phone = binding.Mail = string.Empty;
                    binding.IdUser    = -1;
                    entMail.IsEnabled = entPhone.IsEnabled = true;
                }
            };
            entValue.TextChanged += (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(e.NewTextValue))
                {
                    entValue.Text = "0";
                }
            };
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(ReservationCreateViewModel r)
        {
            var t = await RType();

            r.ReservationTypes = t.ToList();
            var c = await CustomerValidation(r.FirstName, r.LastName, r.PhoneNumber, null);

            if (true)
            {
                var reservation = new Reservation
                {
                    //SittingId = sitting.SittingId,
                    ReservationTypeId = r.ReservationTypeId,
                    Customer          = c,
                    CustomerId        = c.Id,
                    Guests            = r.Guests,
                    DateTime          = r.DateTime,
                };
                if (ModelState.IsValid)
                {
                    await AddReservation(reservation);

                    return(RedirectToAction("ReservationIndex", new { id = reservation.SittingId }));
                }
                else
                {
                    ViewBag.EnterError = "Make sure everything is right before click submit";
                    return(View(r));
                }
            }
            ViewBag.ErrorMessage = "This time or day is not avaiable try other time";
            return(View(r));
        }
Exemplo n.º 6
0
        public IActionResult Create()
        {
            var members = reservationWork.MemberRepository.All();
            var courts  = reservationWork.CourtRepository.All();
            ReservationCreateViewModel viewModel = new ReservationCreateViewModel(members, courts);

            return(View(viewModel));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> ConfirmReservation(Bikes bike)
        {
            ReservationCreateViewModel reserve = new ReservationCreateViewModel {
                Bike = bike
            };

            return(View("Reservation", reserve));
        }
Exemplo n.º 8
0
        // GET: Reservations/Create
        public IActionResult Create()
        {
            ReservationCreateViewModel vm = new ReservationCreateViewModel
            {
                AvailableParkings = _context.Parkings.ToList(),
            };

            return(View(vm));
        }
Exemplo n.º 9
0
 private ReservationDataModel MapToDataModel(ReservationCreateViewModel model)
 {
     return(new ReservationDataModel()
     {
         name = model.name,
         surname = model.surname,
         rideId = model.rideId
     });
 }
        public IActionResult Create(string id)
        {
            var model = new ReservationCreateViewModel()
            {
                PlaneId = id
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(ReservationCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Reservation _reservation = new Reservation
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = model.Name,
                    MiddleName   = model.MiddleName,
                    Surname      = model.Surname,
                    PersonalId   = model.PersonalId,
                    Telephone    = model.Telephone,
                    Nationality  = model.Nationality,
                    FlightTypeId = _context.FlightTypes.FirstOrDefault(f => f.Type == model.TypeName).Id,
                    PlaneId      = model.PlaneId
                };

                var CapacityBuisness = _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityBuisness;
                var CapacityNormal   = _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityNormal;


                if (model.TypeName == "Buisness Class")
                {
                    if (--CapacityBuisness < 0)
                    {
                        ViewBag.Message = $"No more seats left in the Buisness Class";

                        return(View(model));
                    }

                    _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityBuisness--;
                    await _context.SaveChangesAsync();
                }

                else
                {
                    if (--CapacityNormal < 0)
                    {
                        ViewBag.Message = $"No more seats left in the Economy Class";

                        return(View(model));
                    }

                    _context.Flights.FirstOrDefault(f => f.Id == model.PlaneId).CapacityNormal--;
                    await _context.SaveChangesAsync();
                }

                _context.Add(_reservation);
                await _context.SaveChangesAsync();


                return(Redirect("/"));
            }

            return(View(model));
        }
Exemplo n.º 12
0
        public IActionResult Create(string id)
        {
            ReservationCreateViewModel model = new ReservationCreateViewModel()
            {
                FlightId          = id,
                hasBuissnessSeats = this.context.Flights.FindAsync(id).Result.BuissnessClassCapacity == 0 ? false : true
            };

            return(View(model));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Create()
        {
            var ts = await RType();

            var r = new ReservationCreateViewModel
            {
                ReservationTypes = ts.ToList(),
            };

            return(View(r));
        }
Exemplo n.º 14
0
        public IActionResult Create(ReservationCreateViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            var reservation = mapper.Map <Reservation>(viewModel);

            reservationWork.ReservationRepository.Add(reservation);
            reservationWork.Save();
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> AddReservationAsync(ReservationCreateViewModel reservation)
        {
            var id = await _reservationManager.AddAsync(reservation);

            if (id != 0)
            {
                return(Ok(id));
            }
            else
            {
                return(BadRequest("Yolcu sayısı dolmuştur"));
            }
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create(ReservationCreateViewModel model)
        {
            if (this.context.Flights.FindAsync(model.FlightId).Result.EconomyClassCapacity == 0 && !model.isBuissnessClass)
            {
                ModelState.AddModelError(nameof(model.isBuissnessClass), "There aren't any economy seats left");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            string ticketType = model.isBuissnessClass ? "Buissness class" : "Economy class";

            Message message = new Message(new string[] { model.Email }, "Flight reservation",
                                          $"Hello {model.FirstName} {model.LastName},\n" +
                                          $"You have successfully booked your {ticketType} tickets to {this.context.Flights.FindAsync(model.FlightId).Result.FinalLocation}");

            EmailSender emailSender = new EmailSender(this.emailConfiguration);
            await emailSender.SendEmailAsync(message);


            Reservation reservation = new Reservation()
            {
                Id          = Guid.NewGuid().ToString(),
                FirstName   = model.FirstName,
                MiddleName  = model.MiddleName,
                LastName    = model.LastName,
                EGN         = model.EGN,
                PhoneNumber = model.PhoneNumber,
                Nationality = model.Nationality,
                FlightId    = model.FlightId,
                TicketType  = ticketType
            };

            await this.context.AddAsync(reservation);

            if (reservation.TicketType == "Economy class")
            {
                this.context.Flights.FindAsync(reservation.FlightId).Result.EconomyClassCapacity--;
            }
            else
            {
                this.context.Flights.FindAsync(reservation.FlightId).Result.BuissnessClassCapacity--;
            }

            await this.context.SaveChangesAsync();

            return(Redirect("~/Home"));
        }
Exemplo n.º 17
0
        public IActionResult Create()
        {
            ReservationCreateViewModel model = new ReservationCreateViewModel()
            {
                Flights = flightService.GetAllFlights().Select(f => new ReservationFlightCreateViewModel()
                {
                    FlightID            = f.Id,
                    DepartureCity       = f.LeavingFrom,
                    DepartureTime       = f.Departure,
                    DestinationCity     = f.GoingTo,
                    BusinessTicketsLeft = f.BusinessTicketsLeft,
                    TicketsLeft         = f.TicketsLeft
                }).ToList()
            };

            return(View(model));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> Create(ReservationCreateViewModel r)
        {
            var s = await Sitting(r.SittingId);

            var tAarry = await TablesCollection(r.DateTime);

            var ts = await DynamicTableOutput(tAarry);

            var t = await RType();

            r.Tables = ts[s];
            var rs = await Status();

            var rsId = rs.FirstOrDefault(r => r.Description.ToLower().Contains("pending")).Id;

            r.ReservationTypes = t.ToList();
            var c = await CustomerValidation(r.FirstName, r.LastName, r.PhoneNumber, r.Email);

            if (s.Status)
            {
                var reservation = new Reservation
                {
                    SittingId           = r.SittingId,
                    ReservationTypeId   = r.ReservationTypeId,
                    ReservationStatusId = rsId,
                    TableId             = r.TableId,
                    Customer            = c,
                    CustomerId          = c.Id,
                    Guests   = r.Guests,
                    DateTime = r.DateTime,
                    Notes    = r.Notes
                };
                if (ModelState.IsValid)
                {
                    await AddReservation(reservation);

                    return(RedirectToAction("ReservationIndex"));
                }

                ViewBag.EnterError = "Make sure everything is right before click submit";
                return(View(r));
            }
            ViewBag.ErrorMessage = "This time or day is Fully booked try other time";

            return(View(r));
        }
Exemplo n.º 19
0
        public IActionResult Create()
        {
            List <ClientViewModel> clients = context.Clients.Select(c => new ClientViewModel(c.Id, c.FirstName,
                                                                                             c.LastName, c.IsAdult))
                                             .ToList()
                                             .OrderBy(c => c.FirstName)
                                             .ThenBy(c => c.LastName)
                                             .ToList();

            List <RoomViewModel> rooms = context.Rooms.Select(r => new RoomViewModel(r.Id, r.Capacity, r.Type,
                                                                                     r.IsFree, r.Number))
                                         .ToList()
                                         .OrderBy(r => r.Number)
                                         .ToList();

            ReservationCreateViewModel model = new ReservationCreateViewModel(DateTime.Now, DateTime.Now, clients, rooms);

            return(View(model));
        }
        public FlightBooking CreateReservation(ReservationCreateViewModel model)
        {
            FlightBooking reservation = new FlightBooking()
            {
                TicketType   = model.TicketType,
                Flight       = dBContext.Flights.Where(f => f.Id == model.FlightId).First(),
                IsConfirmed  = false,
                TicketsCount = 1,
                Email        = model.Email,
                FirstName    = model.FirstName,
                MiddleName   = model.SecondName,
                Surname      = model.LastName,
                SSN          = model.SSN,
                PhoneNumber  = model.PhoneNumber,
                Nationality  = model.Nationality,
                FlightID     = model.FlightId
            };

            Flight dbFlight = dBContext.Flights.Where(f => f.Id.ToString() == model.FlightId.ToString()).First();

            if (model.TicketType == "Business")
            {
                dbFlight.BusinessTicketsLeft -= model.TicketCount;
            }
            else
            {
                dbFlight.TicketsLeft -= model.TicketCount;
            }

            dBContext.FlightBookings.Add(reservation);
            dBContext.SaveChanges();

            string msg = $@"Thank you for using our services! <br> You have successfuly made a reservation 
            for flight {dbFlight.Id} from {dbFlight.LeavingFrom} to {dbFlight.GoingTo} leaving on {dbFlight.Departure}.
                            Now it's only left for you to confirm it. <br />
                            <a href={"https://localhost:44378"}/FlightBookings/Confirm?id={reservation.Id}>Confirm Reservation</a> <br />
                            <a href={"https://localhost:44378"}/FlightBookings/Delete?id={reservation.Id}>Delete</a>";

            emailSender.SendEmailAsync(reservation.Email, "Reservation Confirmation", msg).GetAwaiter().GetResult();

            return(reservation);
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Create(int id)
        {
            var rts = await RType();

            var s = await Sitting(id);

            var ts = await TablesCollection(s.Start);

            var dts = await DynamicTableOutput(ts);

            var r = new ReservationCreateViewModel
            {
                SittingId        = id,
                ReservationTypes = rts.ToList(),
                Tables           = dts[s],
                DateTime         = s.Start
            };

            return(View(r));
        }
Exemplo n.º 22
0
        public async Task <int> AddAsync(ReservationCreateViewModel model)
        {
            var ride = _rideManager.GetById(model.rideId);

            if (ride.Reservations.Count < ride.seat)
            {
                var dataModel = MapToDataModel(model);
                dataModel.isActive   = true;
                dataModel.createTime = DateTimeOffset.Now.ToUnixTimeSeconds();
                await _repository.AddAsync(dataModel);

                _unitOfWork.SaveChanges();

                return(dataModel.id);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 23
0
        public Reservation CreateReservation(ReservationCreateViewModel model)
        {
            Reservation reservation = new Reservation()
            {
                Email        = model.Email,
                FirstName    = model.FirstName,
                SecondName   = model.SecondName,
                LastName     = model.LastName,
                SSN          = model.SSN,
                PhoneNumber  = model.PhoneNumber,
                Nationality  = model.Nationality,
                TicketType   = model.TicketType,
                Flight       = dBContext.Flights.Where(f => f.FlightID == model.FlightId).First(),
                IsConfirmed  = false,
                TicketsCount = model.TicketCount,
                FlightID     = model.FlightId
            };

            Flight dbFlight = dBContext.Flights.Where(f => f.FlightID == model.FlightId).First();

            if (model.TicketType == "Business")
            {
                dbFlight.BusinessTicketsLeft -= model.TicketCount;
            }
            else
            {
                dbFlight.TicketsLeft -= model.TicketCount;
            }

            dBContext.Reservations.Add(reservation);
            dBContext.SaveChanges();

            string msg = $@"Confirmation for flight from {dbFlight.DepartureCity} to {dbFlight.DestinationCity} <br />
                            <a href={"https://localhost:44361"}/Reservation/Confirm?id={reservation.ReservationID}>Confirm</a> <br />
                            <a href={"https://localhost:44361"}/Reservation/Delete?id={reservation.ReservationID}>Delete</a>";

            emailSender.SendEmailAsync(reservation.Email, "Reservation Confirmation", msg).GetAwaiter().GetResult();

            return(reservation);
        }
Exemplo n.º 24
0
        public IActionResult Create(int?businessID)
        {
            if (businessID == null || !businessID.HasValue)
            {
                return(NotFound());
            }
            Business business = _businessManager.GetBusinessForDetails(businessID.Value);

            if (business == null)
            {
                return(NotFound());
            }
            var addVM = new ReservationCreateViewModel
            {
                FoundTable        = true,
                BusinessID        = businessID.Value,
                BusinessToReserve = business,
                BusinessHours     = _businessManager.GetBusinessHours(business.ID).Data,
            };

            return(View(addVM));
        }
Exemplo n.º 25
0
        public async Task <ActionResult> Reserve(ReservationCreateViewModel res)
        {
            TempData["message"] = string.Empty;
            //if (res == null) return View(new ReservationCreateViewModel());
            Reservations reserve = new Reservations
            {
                Bikes     = res.Bike,
                BeginDate = res.BeginDate,
                EndDate   = res.EndDate
            };



            bool succeeded = await repo.AddReservation(reserve);

            //if (succeeded)
            //{
            //    return RedirectToAction("NewReservation");
            //}

            //return View("BikeIndex");
            return(RedirectToAction("ReserveComplete"));
        }
Exemplo n.º 26
0
        public IActionResult Create(ReservationCreateViewModel vm)
        {
            if (ModelState.IsValid)
            {
                string userID = User.FindFirstValue(ClaimTypes.NameIdentifier);
                Table  table  = _tableManager.GetFreeTable(vm.BusinessID, vm.AmountOfGuests, vm.ReservationDate.Value);
                if (table != null)
                {
                    Reservation newReservation = new Reservation
                    {
                        UserID              = userID,
                        TableID             = table.ID,
                        AmountOfGuests      = vm.AmountOfGuests,
                        ReservationDateFrom = vm.ReservationDate,
                        ReservationDateTo   = vm.ReservationDate.Value.AddHours(1)
                    };
                    _reservationManager.CreateReservation(newReservation);
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    vm.FoundTable = false;
                }
            }

            // Can't pass objects with vm -> opnieuw opvragen
            Business business = _businessManager.GetBusinessForDetails(vm.BusinessID);

            if (business == null)
            {
                return(NotFound());
            }
            vm.BusinessToReserve = business;
            vm.BusinessHours     = _businessManager.GetBusinessHours(vm.BusinessID).Data;
            return(View(vm));
        }
Exemplo n.º 27
0
        public IActionResult Create(ReservationCreateViewModel model)
        {
            if (model.CheckInDate < DateTime.Now)
            {
                ModelState.AddModelError("CheckInDate", "Check-in date cannot be in the past.");
            }

            if (model.CheckOutDate < DateTime.Now)
            {
                ModelState.AddModelError("CheckOutDate", "Check-out date cannot be in the past.");
            }

            if (ModelState.IsValid)
            {
                foreach (var previousReservation in context.Reservations)
                {
                    if (previousReservation.Room.Id == model.ChoosenRoom &&
                        ((previousReservation.CheckInDate <= model.CheckInDate &&
                          model.CheckInDate < previousReservation.CheckOutDate) ||
                         (previousReservation.CheckInDate < model.CheckOutDate &&
                          model.CheckInDate <= previousReservation.CheckOutDate)))
                    {
                        return(Redirect("~/Reservation/RoomNotFree"));;
                    }
                }

                Room room = context.Rooms.Find(model.ChoosenRoom);

                if (model.ChoosenClients.Count > room.Capacity)
                {
                    return(Redirect("~/Reservation/TooManyPeople"));
                }

                User creator = context.Users.Find(userManager.GetUserId(User));

                Reservation reservation = new Reservation(room, creator, new List <ClientReservation>(), model.CheckInDate, model.CheckOutDate, model.IsBreakfastIncluded, model.IsAllInclusive, 0);

                reservation.ClientReservations = model.ChoosenClients.Select(c => context.Clients.Find(c))
                                                 .Select(c => new ClientReservation(c.Id, c, reservation.Id, reservation)).ToList();

                foreach (var client in reservation.ClientReservations.Select(cr => cr.Client))
                {
                    if (client.IsAdult)
                    {
                        reservation.Price += reservation.Room.AdultPrice;
                    }
                    else
                    {
                        reservation.Price += reservation.Room.ChildPrice;
                    }
                }

                context.Reservations.Add(reservation);
                context.SaveChanges();

                string body = ReservationDetaisEmailBody(reservation);

                foreach (var client in reservation.ClientReservations.Select(cl => cl.Client.Email))
                {
                    SendEmail(client, "New hotel reservation", body);
                }

                return(Redirect("~/Reservation/Details/" + reservation.Id));
            }

            model.Clients = context.Clients.Select(c => new ClientViewModel()
            {
                FirstName = c.FirstName,
                LastName  = c.LastName,
                Id        = c.Id,
                IsAdult   = c.IsAdult
            }).ToList();

            model.Rooms = context.Rooms.Select(r => new RoomViewModel()
            {
                Id       = r.Id,
                Capacity = r.Capacity,
                Type     = r.Type,
                Number   = r.Number
            }).ToList();

            return(View(model));
        }
Exemplo n.º 28
0
 public ReservationCreateView(ReservationModel reservation)
 {
     InitializeComponent();
     BindingContext = new ReservationCreateViewModel(this, reservation);
 }