Ejemplo n.º 1
0
        public ActionResult RoomReservation()
        {
            IRepository repository = new CommunicationWithDataBase();

            logger.Debug($"Обращение к базе данных, получение комнат");
            List <Room> rooms = repository.GetAllRooms();

            ViewData["RoomClassItems"]     = FormingSelectItems.GetRoomClassRoomItems(rooms);
            ViewData["CountOfPlacesItems"] = FormingSelectItems.GetCurrentRoomCountOfPlacesItems(rooms);

            return(View(rooms));
        }
Ejemplo n.º 2
0
        public ActionResult RoomReservation(FormCollection form)
        {
            IRepository repository = new CommunicationWithDataBase();

            int      roomClassId   = Convert.ToInt32(form["RoomClass"]);
            int      countOfPlaces = Convert.ToInt32(form["CountOfPlaces"]);
            DateTime startDate     = new DateTime();
            DateTime endDate       = new DateTime();

            try
            {
                startDate = Convert.ToDateTime(form["StartDate"]);
                endDate   = Convert.ToDateTime(form["EndDate"]);
            }
            catch
            {
                ModelState.AddModelError("DateValidationError", "Даты указаны некорректно");
                logger.Error($"Ошибка. Невозможно конвертировать дату");
            }

            if (startDate < DateTime.Now || startDate >= endDate)
            {
                ModelState.AddModelError("DateValidationError", "Даты указаны некорректно");
            }

            if (startDate.AddDays(14) < endDate)
            {
                ModelState.AddModelError("DateValidationError", "Проживание в отеле допустимо не более 2х недель");
            }

            if (ModelState.IsValid)
            {
                logger.Debug($"Обращение к базе данных, создание запроса на поселение");
                string userLogin = User.Identity.Name;
                repository.CreateRequest(userLogin, roomClassId, countOfPlaces, startDate, endDate);
                logger.Info($"Пользователем создан новый запрос на поселение");
                return(RedirectToAction("Index"));
            }

            logger.Debug($"Обращение к базе данных, получение комнат");
            List <Room> rooms = repository.GetAllRooms();

            ViewData["RoomClassItems"]     = FormingSelectItems.GetRoomClassRoomItems(rooms);
            ViewData["CountOfPlacesItems"] = FormingSelectItems.GetCurrentRoomCountOfPlacesItems(rooms);

            return(View());
        }