コード例 #1
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"));
        }
コード例 #2
0
        public void CustomerRequestService_Can_Create_Room()
        {
            //Arrange
            var customerRequest = new CustomerRequest
            {
                DateFrom    = DateTime.Now,
                DateTo      = DateTime.Now,
                HotelUserId = "1"
            };

            _unitOfWork.Setup(m => m.CustomerRequests.Create(customerRequest));
            // Act
            _customerRequestService.Create(customerRequest);
            // Assert
            _unitOfWork.Verify(v => v.CustomerRequests.Create(customerRequest), Times.Once());
            _unitOfWork.Verify(x => x.Save(), Times.Once());
        }