public async Task GetBookings_Should_ReturnListOfBookingRequests()
        {
            // Arrange
            var clientId    = Guid.NewGuid();
            var customerId1 = Guid.NewGuid();
            var customerId2 = Guid.NewGuid();
            await repo.Create(new BookingRequest(), customerId1, clientId);

            await repo.Create(new BookingRequest(), customerId2, clientId);

            var sut = new BookingRequestService(repo, null);
            // Act
            var result = await sut.GetBookings(clientId);

            // Assert
            Assert.IsType <List <BookingRequest> >(result);
        }
Esempio n. 2
0
        public ActionResult Create(CreateBookingRequestViewModel model)
        {
            try
            {
                var startDate     = Convert.ToDateTime(model.CheckinDate);
                var endDate       = Convert.ToDateTime(model.CheckOutDate);
                var roomTypes     = _roomTypeRepo.FindAll();
                var roomTypeItems = roomTypes.Select(q => new SelectListItem
                {
                    Text  = q.RoomName,
                    Value = q.RoomTypeId.ToString()
                });
                model.RoomType = roomTypeItems;
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                if (DateTime.Compare(startDate, endDate) > 1)
                {
                    ModelState.AddModelError("", "CheckinDate cannot be further than the CheckOutDate");
                    return(View(model));
                }
                var employee      = _userManager.GetUserAsync(User).Result;
                var allocation    = _bookingRepo.GetBookingsByEmployeeAndType(employee.Id, model.RoomTypeId);//id to employee id
                int daysRequested = (int)(startDate - endDate).TotalDays;

                if (daysRequested > allocation.NumberOfDays)
                {
                    ModelState.AddModelError("", "You do not have sufficient days to make this request");
                    return(View(model));
                }

                var bookingRequestModel = new BookingRequestViewModel
                {
                    EmployeeBookingRoomId = employee.Id,
                    CheckinDate           = startDate,
                    CheckOutDate          = endDate,
                    Approved      = null,
                    DateRequested = DateTime.Now,
                    DateActioned  = DateTime.Now,
                    RoomTypeId    = model.RoomTypeId
                };
                var bookingRequest = _mapper.Map <BookingRequest>(bookingRequestModel);
                var isSuccess      = _bookingRequestRepo.Create(bookingRequest);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Something went wrong WITH SUBMITTING RECORD");
                    return(View(model));
                }
                return(RedirectToAction("MyBooking"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Something went wrong");
                return(View(model));
            }
        }
Esempio n. 3
0
        public async Task <Guid> Create(CreateBookingRequestDto request)
        {
            var bookingRequest = new BookingRequest
            {
                ItemId    = request.ItemId,
                UserId    = request.UserId,
                StartDate = request.StartDate,
                EndDate   = request.EndDate,
                Comment   = request.Comment,
            };

            await _repository.Create(bookingRequest);

            await _context.SaveChangesAsync();

            return(bookingRequest.Id);
        }
        public async Task <BookingRequest> CreateBooking(BookingRequest_Create req, Guid clientId)
        {
            if (req.CustomerId == Guid.Empty)
            {
                throw new Exception("CustomerId was not set");
            }
            var customer = await customers.GetById(req.CustomerId.ToString(), clientId.ToString());

            var vehicle = customer?.CustomerData?.MyVehicles?.FirstOrDefault(x => x.Registration == req.Registration);

            try
            {
                var booking = new BookingRequest
                {
                    Registration          = req.Registration,
                    MOT                   = req.MotRequest,
                    Service               = req.ServiceRequest,
                    PreferedDate          = req.PreferedDate,
                    PreferedTime          = req.PreferedTime,
                    Message               = req.Message,
                    Confirmed             = false,
                    Cancelled             = false,
                    ConfirmationEmailSent = false,
                    Vehicle               = vehicle,
                    Customer              = new BookingCustomer
                    {
                        Id            = Guid.Parse(customer.Id),
                        ClientId      = Guid.Parse(customer.ClientId.Id),
                        FirstName     = customer.FirstName,
                        LastName      = customer.LastName,
                        EmailAddress  = customer.EmailAddress,
                        ContactNumber = customer.ContactNumber
                    },
                    RequestDate = DateTime.UtcNow,
                };
                return(await bookings.Create(booking, req.CustomerId, clientId));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw;
            }
        }