示例#1
0
        public ActionResult ConfirmRequest(int?aprtId, int?reqId)
        {
            if (ApartmentContainer.roomsForPickIds.Contains(aprtId.Value) && ApartmentContainer.requestId == reqId.Value)
            {
                try
                {
                    var request = Mapper.Map <RequestDTO, RequestViewModel>(requestService.GetRequest(reqId));

                    if (apartmentService.IsCorrectApartmentForPickedDate(aprtId, request.DateOfArrival, request.DaysOfStay))
                    {
                        requestService.ConfirmRequest(reqId.Value, aprtId.Value, User.Identity.GetUserId());
                    }
                    else
                    {
                        return(View("NoAvailableApartments"));
                    }
                }
                catch (ValidationException ex)
                {
                    // Залогировать эксепшн
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View("IncorrectData"));
            }
        }
        public ActionResult PickApartment(int?id)
        {
            try
            {
                if (id == null || BookingContainer.Date == null)
                {
                    return(View("InvalidData"));
                }

                var apartment = Mapper.Map <ApartmentDTO, ApartmentViewModel>(apartmentService.GetApartment(id));

                if (apartmentService.IsCorrectApartmentForPickedDate(id, BookingContainer.Date, BookingContainer.Days))
                {
                    bookingService.MakeBooking(new BookingDTO
                    {
                        ApartmentClassId = apartment.ApartmentClassId,
                        ApartmentId      = id.Value,
                        DateOfArrival    = BookingContainer.Date,
                        DaysOfArrival    = BookingContainer.Days,
                        UserId           = User.Identity.GetUserId()
                    });

                    return(RedirectToAction("Index"));
                }
                else
                {
                    if (apartment.ApartmentClassId == 1)
                    {
                        ViewBag.Error = "No free luxury apartments for date " + BookingContainer.Date.ToShortDateString() + " ";
                    }
                    else if (apartment.ApartmentClassId == 1)
                    {
                        ViewBag.Error = "No free comfort apartments for date " + BookingContainer.Date.ToShortDateString() + " ";
                    }
                    else if (apartment.ApartmentClassId == 1)
                    {
                        ViewBag.Error = "No free economy apartments for date " + BookingContainer.Date.ToShortDateString() + " ";
                    }

                    return(View("MakeBooking"));
                }
            }
            catch (ValidationException ex)
            {
                // Залогировать эксепшн
            }

            return(HttpNotFound());
        }