Beispiel #1
0
 public ActionResult NewReservation(int id)
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer")
     {
         int userId    = Convert.ToInt32(Session["Id"]);
         var viewModel = new NewReservationViewModel
         {
             Reservation = new Reservation
             {
                 Automobile = _context.Automobiles
                              .Include(a => a.Gearshift)
                              .Include(a => a.CarBody)
                              .Include(a => a.NumberOfDoor).Single(a => a.Id == id),
                 User = _context.Users.Single(u => u.Id == userId)
             },
             Offers       = _context.Offers.Where(o => o.AutomobileId == id).ToList(),
             Reservations = _context.Reservations.Where(r => r.AutomobileId == id).ToList()
         };
         return(View("NewReservation", viewModel));
     }
     else
     {
         return(HttpNotFound());
     }
 }
Beispiel #2
0
        public NewReservationPage()
        {
            InitializeComponent();
            BindingContext = new NewReservationViewModel();

            datePicker.MinimumDate = DateTime.Now;
        }
Beispiel #3
0
 public ConfirmReservationPage(NewReservationViewModel newReservationViewModel)
 {
     InitializeComponent();
     BindingContext = model = new ConfirmReservationViewModel {
         NewReservation = newReservationViewModel
     };
 }
        public ActionResult Save(NewReservationViewModel ReservationViewModel)
        {
            if (ReservationViewModel.Reservation.IdReservation == 0)
            {
                var userId = User.Identity.GetUserId();
                var car    = _context.Cars.Single(c => c.UserId.Id == userId);
                ReservationViewModel.Reservation.Car       = car;
                ReservationViewModel.Reservation.Mechanics = new List <Mechanics>();
                ReservationViewModel.Reservation.Service   =
                    _context.Services.Single(s => s.IdService == ReservationViewModel.ServiceId);
                foreach (var mechanicID in ReservationViewModel.SelectedMechanics)
                {
                    var mechanic = _context.Mechanics.Single(m => m.IdMechanic == mechanicID);
                    ReservationViewModel.Reservation.Mechanics.Add(mechanic);
                }
                _context.Reservations.Add(ReservationViewModel.Reservation);
            }
            else
            {
                var reservationInDb = _context.Reservations.Single(r => r.IdReservation == ReservationViewModel.Reservation.IdReservation);

                reservationInDb.Date    = ReservationViewModel.Reservation.Date;
                reservationInDb.Service = _context.Services.Single(s => s.IdService == ReservationViewModel.ServiceId);
                foreach (var mechanicID in ReservationViewModel.SelectedMechanics)
                {
                    var mechanic = _context.Mechanics.Single(m => m.IdMechanic == mechanicID);
                    reservationInDb.Mechanics.Add(mechanic);
                }
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Reservations"));
        }
Beispiel #5
0
 public ActionResult DeleteResCheck(int id)
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer")
     {
         int index = id;
         if (index < Lists.CurrentlyRes.Count())
         {
             Lists.CurrentlyRes.RemoveAt(index);
             int userId    = Convert.ToInt32(Session["Id"]);
             var viewModel = new NewReservationViewModel
             {
                 Reservations = Lists.CurrentlyRes.Where(r => r.UserId == userId)
             };
             if (_context.Reservations.Count() > 0)
             {
                 viewModel.YourReservations = _context.Reservations.Where(r => r.UserId == userId).Include(r => r.Automobile);
             }
             else
             {
                 viewModel.YourReservations = new List <Reservation>();
             }
             int countChart = Convert.ToInt32(Session["CountChart"]);
             --countChart;
             Session["CountChart"] = countChart.ToString();
             return(View("YourReservations", viewModel));
         }
         return(HttpNotFound());
     }
     return(HttpNotFound());
 }
        public IActionResult New([FromForm] NewReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!_reservationRepository.IsDateAvailable(model.RoomId, model.SelectedReservationTime))
                {
                    TempData["ErrorMessage"] = "Selected date is not available. Please choose another time.";
                }
                else
                {
                    return(RedirectToAction(nameof(Confirmation), new { roomId = model.RoomId, reservationDate = model.SelectedReservationTime }));
                }
            }

            Room room = _roomRepository.GetById(model.RoomId);

            List <ReservationDateTime> dates = _reservationService.GetReservationDateTimes(
                DateTime.Today.AddHours(room.OpenFrom),
                DateTime.Today.AddHours(room.OpenTo),
                _reservationRepository.GetUnavailableDates(room.Id, DateTime.Today));

            model.Dates  = dates;
            model.Room   = room;
            model.RoomId = room.Id;

            return(View(model));
        }
 public NewReservationPage(ScreeningDto screening)
 {
     InitializeComponent();
     _screening     = screening;
     BindingContext = model = new NewReservationViewModel {
         Screening = screening
     };
 }
Beispiel #8
0
        public ActionResult NewReservation(NewReservationViewModel model)
        {
            try
            {
                var room     = _roomsManagement.Get(r => r.ID == model.Book.RoomID);
                var roomType = room.RoomTypeID;

                var books = _booksManagement.GetAll(b => b.RoomID == room.ID).OrderByDescending(b => b.ArrivalDate).AsNoTracking().ToList();

                if (books.Count > 0)
                {
                    foreach (var book in books)
                    {
                        if (book.CustomerID != model.Book.CustomerID && !(DateHelper.AvailableDate(model.Book.ArrivalDate, model.Book.DepartureDate, book.ArrivalDate, book.DepartureDate)))
                        {
                            var roomNo = _roomsManagement.Get(r => r.ID == model.Book.RoomID).RoomNo;
                            throw new UnavailableRoomException(roomNo);
                        }
                    }
                }

                if (model.Book.ID == 0)
                {
                    model.Book.BookingDate = DateTime.Now;
                    model.Book.EmployeeID  = (User as CustomPrincipal).ID;
                }

                model.Book.Night = (int)(model.Book.DepartureDate - model.Book.ArrivalDate).TotalDays;
                if (model.Book.Night <= 0)
                {
                    throw new BookingDateException(model.Book.ArrivalDate, model.Book.DepartureDate);
                }

                model.Book.Discount = model.Discount / 100;
                model.Book.Price    = _roomTypesManagement.Get(r => r.ID == roomType).Price;

                _booksManagement.AddOrUpdate(model.Book);
                this.SuccessMessage("Reservation has been saved!");
            }
            catch (UnavailableRoomException e)
            {
                this.ErrorMessage(e.Message);
                return(RedirectToAction("NewReservation", "ReservationManagement"));
            }
            catch (BookingDateException e)
            {
                this.ErrorMessage(e.Message);
                return(RedirectToAction("NewReservation", "ReservationManagement"));
            }
            catch (Exception e)
            {
                this.ErrorMessage($"Reservation could not be saved! ({e.Message})");
            }

            return(RedirectToAction("Index"));
        }
Beispiel #9
0
        public async Task <IActionResult> Create()
        {
            var auxViewModel = new NewReservationViewModel();

            _manageReservations.GetOperationsFromDatabase(auxViewModel);
            var user = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.CarsList = _manageCars.GetUserCars(user);
            return(View(auxViewModel));
        }
Beispiel #10
0
        public void SetUpTheReservation(Reservation reservation, NewReservationViewModel newReservationViewModel)
        {
            reservation.Car                   = FindTheCar(newReservationViewModel);
            reservation.StartTime             = newReservationViewModel.StartTime;
            reservation.OperationReservations = FindOperationReservations(reservation, SearchOperation(newReservationViewModel));
            _helpNewReservation.SetUpReservation(reservation, _unitOfWork.GateRepository.GetAll().ToList());

            _unitOfWork.ReservationRepository.Insert(reservation);
            _unitOfWork.Commit();
        }
Beispiel #11
0
        private Car FindTheCar(NewReservationViewModel newReservationViewModel)
        {
            var cars = _unitOfWork.CarRepository.GetAll().ToList();
            var car  = cars.FirstOrDefault(aux => aux.CarId == newReservationViewModel.CarId);

            if (car == null)
            {
                return(null);
            }
            return(car);
        }
Beispiel #12
0
        public async Task <IActionResult> Create(NewReservationViewModel newReservationViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                var reservation = new Reservation();
                _manageReservations.AddReservation(newReservationViewModel, reservation);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newReservationViewModel));
        }
        public ActionResult Create(ApplicationUser user, ReservationDateRangeViewModel reservationDateRangeViewModel)
        {
            reservationDateRangeViewModel.UserType = user.Type;
            CheckDateRangeModel(reservationDateRangeViewModel, reservationDateRangeViewModel.StartDate, reservationDateRangeViewModel.EndDate, false);
            var materials = user.WishList.Materials.Select(m => new ReservationDetailSelectionViewModel(
                                                               m,
                                                               m.GetAvailableIdentifiersCount(reservationDateRangeViewModel.StartDate, reservationDateRangeViewModel.EndDate, user.Type),
                                                               0));
            var materialsPicker = new NewReservationMaterialsViewModel(materials, false);
            var wrapper         = new NewReservationViewModel(reservationDateRangeViewModel, materialsPicker);

            return(View(wrapper));
        }
Beispiel #14
0
        private List <Operation> SearchOperation(NewReservationViewModel newReservationViewModel)
        {
            var operations = new List <Operation>();

            foreach (var operation in newReservationViewModel.Operations)
            {
                if (operation.IsChecked)
                {
                    var auxOperation = _unitOfWork.OperationRepository.GetById(operation.OperationId);
                    operations.Add(auxOperation);
                }
            }
            return(operations);
        }
Beispiel #15
0
 public ActionResult ValidReservation()
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer")
     {
         int userId    = Convert.ToInt32(Session["Id"]);
         var viewModel = new NewReservationViewModel
         {
             YourReservations = _context.Reservations.Where(r => r.UserId == userId)
                                .Include(r => r.User)
                                .Include(r => r.Automobile).ToList()
         };
         return(View(viewModel));
     }
     return(HttpNotFound());
 }
        public ActionResult NewReservation()
        {
            var servicesList  = _context.Services.ToList();
            var userId        = User.Identity.GetUserId();
            var car           = _context.Cars.Single(c => c.UserId.Id == userId);
            var mechanicsList = _context.Mechanics.ToList();
            var viewModel     = new NewReservationViewModel
            {
                Reservation = new Reservations(),
                Services    = servicesList,
                Mechanics   = mechanicsList,
                Car         = car
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> New(NewReservationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var reservation = new Reservation()
                {
                    Book       = await _db.Books.FindAsync(model.BookId),
                    Client     = await _db.Clients.FindAsync(model.ClientId),
                    TargetDate = model.TargetDate
                };
                _db.Reservations.Add(reservation);
                _db.SaveChanges();
                return(Redirect("/books/index"));
            }

            return(RedirectToAction("New", new { Id = model.BookId }));
        }
Beispiel #18
0
        public ActionResult NewReservation(int?id)
        {
            NewReservationViewModel model = new NewReservationViewModel()
            {
                RoomList     = _roomsManagement.GetAll().ToList(),
                RoomTypeList = _roomTypesManagement.GetAll().ToList(),
                CustomerList = _customersManagement.GetAll().OrderBy(c => c.Name).ToList()
            };

            if (id == null)
            {
                model.Book = new Books();
            }
            else
            {
                model.Book = _booksManagement.Get(d => d.ID == id);
            }

            return(View(model));
        }
Beispiel #19
0
 public ActionResult UsersReservation(int id)
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Admin")
     {
         var userInDb = _context.Users.FirstOrDefault(u => u.Id == id);
         if (userInDb != null)
         {
             var viewModel = new NewReservationViewModel
             {
                 Reservations = _context.Reservations.Include(r => r.Automobile).Where(r => r.UserId == id).ToList(),
                 User         = userInDb
             };
             return(View(viewModel));
         }
         else
         {
             return(HttpNotFound());
         }
     }
     return(HttpNotFound());
 }
Beispiel #20
0
 public ActionResult DeleteYourRes(int id)
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer")
     {
         var reservationInDb = _context.Reservations.Single(r => r.Id == id);
         int userId          = Convert.ToInt32(Session["Id"]);
         if (reservationInDb != null)
         {
             _context.Reservations.Remove(reservationInDb);
             _context.SaveChanges();
             var viewModel = new NewReservationViewModel
             {
                 YourReservations = _context.Reservations.Where(r => r.UserId == userId).Include(r => r.Automobile)
                                    .Include(r => r.User).ToList()
             };
             return(View("ValidReservation", viewModel));
         }
         return(HttpNotFound());
     }
     return(HttpNotFound());
 }
Beispiel #21
0
 public ActionResult YourReservations()
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer")
     {
         int userId    = Convert.ToInt32(Session["Id"]);
         var viewModel = new NewReservationViewModel
         {
             Reservations = Lists.CurrentlyRes.Where(r => r.UserId == userId)
         };
         if (_context.Reservations.Count() > 0)
         {
             viewModel.YourReservations = _context.Reservations.Where(r => r.UserId == userId).Include(r => r.Automobile);
         }
         else
         {
             viewModel.YourReservations = new List <Reservation>();
         }
         return(View(viewModel));
     }
     return(HttpNotFound());
 }
        public IActionResult New(long id)
        {
            Room room = _roomRepository.GetById(id);

            if (room == null)
            {
                return(RedirectToAction("Index", "Rooms"));
            }

            List <ReservationDateTime> dates = _reservationService.GetReservationDateTimes(
                DateTime.Today.AddHours(room.OpenFrom),
                DateTime.Today.AddHours(room.OpenTo),
                _reservationRepository.GetUnavailableDates(room.Id, DateTime.Today));

            NewReservationViewModel model = new NewReservationViewModel();

            model.Room   = room;
            model.RoomId = room.Id;
            model.Dates  = dates;

            return(View(model));
        }
Beispiel #23
0
 public ActionResult DeleteYourRes(int id)
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Admin")
     {
         var reservationInDb = _context.Reservations.Single(r => r.Id == id);
         int userId          = reservationInDb.UserId;
         if (reservationInDb != null)
         {
             _context.Reservations.Remove(reservationInDb);
             _context.SaveChanges();
             var viewModel = new NewReservationViewModel
             {
                 Reservations = _context.Reservations.Where(r => r.UserId == userId).Include(r => r.Automobile)
                                .Include(r => r.User).ToList(),
                 User = _context.Users.FirstOrDefault(u => u.Id == userId)
             };
             return(View("UsersReservation", viewModel));
         }
         return(HttpNotFound());
     }
     return(HttpNotFound());
 }
Beispiel #24
0
 public ActionResult BuyReservation()
 {
     if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer" && Lists.CurrentlyRes.Count() > 0)
     {
         for (int i = 0; i < Lists.CurrentlyRes.Count(); i++)
         {
             Lists.CurrentlyRes[i].Automobile = null;
             _context.Reservations.Add(Lists.CurrentlyRes[i]);
         }
         int countChart = Convert.ToInt32(Session["CountChart"]);
         countChart           -= Lists.CurrentlyRes.Count();
         Session["CountChart"] = countChart.ToString();
         Lists.CurrentlyRes.Clear();
         int userId = Convert.ToInt32(Session["Id"]);
         _context.SaveChanges();
         var viewModel = new NewReservationViewModel
         {
             YourReservations = _context.Reservations.Where(r => r.UserId == userId).Include(r => r.Automobile),
             Reservations     = new List <Reservation>()
         };
         return(View("YourReservations", viewModel));
     }
     return(HttpNotFound());
 }
        public ActionResult Edit(int id)
        {
            var reservation = _context.Reservations.SingleOrDefault(m => m.IdReservation == id);

            if (reservation == null)
            {
                return(HttpNotFound());
            }

            var servicesList  = _context.Services.ToList();
            var userId        = User.Identity.GetUserId();
            var car           = _context.Cars.Single(c => c.UserId.Id == userId);
            var mechanicsList = _context.Mechanics.ToList();

            var reservationModel = new NewReservationViewModel()
            {
                Reservation = reservation,
                Services    = servicesList,
                Mechanics   = mechanicsList,
                Car         = car
            };

            return(View("NewReservation", reservationModel));
        }
Beispiel #26
0
 public void AddReservation(NewReservationViewModel newReservationViewModel, Reservation reservation)
 {
     _newReservation.SetUpTheReservation(reservation, newReservationViewModel);
 }
Beispiel #27
0
        public ActionResult Save(Reservation reservation)
        {
            if (Session["Id"] != null && Session["UserRank"].ToString() == "Customer")
            {
                if (!ModelState.IsValid)
                {
                    reservation.Automobile = _context.Automobiles.Include(a => a.Gearshift)
                                             .Include(a => a.CarBody)
                                             .Include(a => a.NumberOfDoor).Single(a => a.Id == reservation.AutomobileId);
                    reservation.User = _context.Users.Single(u => u.Id == reservation.UserId);
                    var viewModel = new NewReservationViewModel
                    {
                        Reservation = reservation,
                        Offers      = _context.Offers.Where(o => o.AutomobileId == reservation.AutomobileId).ToList()
                    };
                    int userId = Convert.ToInt32(Session["Id"]);
                    if (_context.Reservations.Count() > 0)
                    {
                        viewModel.Reservations = _context.Reservations.Where(r => r.AutomobileId == reservation.AutomobileId).Include(r => r.Automobile);
                    }
                    else
                    {
                        viewModel.Reservations = new List <Reservation>();
                    }
                    return(View("NewReservation", viewModel));
                }
                else
                {
                    double total = 0;
                    foreach (var offer in _context.Offers)
                    {
                        if (offer.BeginDate.Date <= reservation.BeginDate.Date &&
                            offer.DateStop.Date >= reservation.DateStop.Date && offer.AutomobileId == reservation.AutomobileId)
                        {
                            total = (reservation.DateStop - reservation.BeginDate).TotalDays * offer.PriceAtDay;
                        }
                    }
                    int countChart = Convert.ToInt32(Session["CountChart"]);
                    ++countChart;
                    Session["CountChart"]  = countChart.ToString();
                    reservation.TotalPrice = total;
                    reservation.Automobile = _context.Automobiles.Single(a => a.Id == reservation.AutomobileId);
                    Lists.CurrentlyRes.Add(reservation);
                    int userId = Convert.ToInt32(Session["Id"]);
                    List <Reservation> example = new List <Reservation>();
                    var model = new NewReservationViewModel
                    {
                        Reservations = Lists.CurrentlyRes.Where(r => r.UserId == reservation.UserId)
                    };
                    if (_context.Reservations.Count() > 0)
                    {
                        model.YourReservations = _context.Reservations.Where(r => r.UserId == userId).Include(r => r.Automobile);
                    }
                    else
                    {
                        model.YourReservations = new List <Reservation>();
                    }
                    Session["NewReservation"] = "true";

                    return(RedirectToAction("YourReservations", model));
                }
            }
            return(HttpNotFound());
        }
Beispiel #28
0
 public void GetOperationsFromDatabase(NewReservationViewModel newReservationViewModel)
 {
     newReservationViewModel.Operations = _unitOfWork.OperationRepository.GetAll().ToList();
 }