예제 #1
0
        public void CustomerRequestStatusService_Get_All_CustomerRequestStatus()
        {
            // Act
            var customerRequestActual = _customerRequestStatusService.GetAll();

            // Assert
            Assert.AreEqual(4, customerRequestActual.Count(), "The room count is not correct");
        }
예제 #2
0
        public ActionResult CustomerRequest(CustomerRequestViewModel customerRequestViewModel)
        {
            if (customerRequestViewModel == null)
            {
                return(HttpNotFound());
            }
            //Validation of entered dates
            if (customerRequestViewModel.DateFrom > customerRequestViewModel.DateTo)
            {
                return(RedirectToAction("CustomerRequest", "Request",
                                        new
                {
                    errorMessage = "Arrival date can not be later than the date of departure. Enter dates correctly"
                }));
            }
            //Validation field sleeps
            if (customerRequestViewModel.Sleeps <= 0)
            {
                return(RedirectToAction("CustomerRequest", "Request",
                                        new
                {
                    errorMessage = "Field sleeps cannot be less than zero"
                }));
            }
            var userId = User.Identity.GetUserId();

            customerRequestViewModel.CustomerRequestStatusId =
                _customerRequestStatusService.GetAll().First(x => x.Name == "New request").Id;
            try
            {
                if (ModelState.IsValid)
                {
                    var customerRequest = new CustomerRequest
                    {
                        CustomerRequestStatusId = customerRequestViewModel.CustomerRequestStatusId,
                        DateTo      = customerRequestViewModel.DateTo,
                        DateFrom    = customerRequestViewModel.DateFrom,
                        Sleeps      = customerRequestViewModel.Sleeps,
                        RoomTypeId  = customerRequestViewModel.RoomTypeId,
                        HotelUserId = userId
                    };
                    Logger.Log.Debug("Add new customer request");
                    _customerRequestServices.Create(customerRequest);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error("Error adding new customer request", ex);
                ModelState.AddModelError(ex.Source, ex.Message);
            }

            return(RedirectToAction("Index", "Home"));
        }