示例#1
0
        public bool CreateBooking(Booking entity)
        {
            var days = _bookingrepository.GetBusyDays(entity.EmployeeId);

            if (entity.date.CompareTo(days[0]) == -1 || entity.date.CompareTo(days[days.Count - 1]) == 1)
            {
                return(false);
            }

            var busyhours = _bookingrepository.GetBusyTimes(entity.EmployeeId, entity.date);

            for (int i = 0; i < busyhours.Count - 1; i++)
            {
                if (busyhours[i].CompareTo(entity.date) == 0)
                {
                    return(false);
                }
            }

            if (entity.CustomerId == entity.EmployeeId)
            {
                return(false);
            }

            _bookingrepository.Create(entity);
            return(true);
        }
示例#2
0
        public async Task <BookingResponse> CreateInView(BookingDTO newBooking, Guid viewId)
        {
            var isAdmin = _aadService.IsAdmin();
            var booking = BookingMapper.Map(newBooking);

            if (!await _itemRepository.CheckIfAvailableToBook(booking))
            {
                string errorMessage = "Too many concurrent bookings";
                Log.Error(errorMessage);
                return(new BookingResponse(errorMessage));
            }
            if (!isAdmin && !_viewRepository.CheckIfAllowedToBook(booking.ItemId, viewId))
            {
                string errorMessage = $"Item {booking.Item.Name} can't be booked.";
                Log.Error(errorMessage);
                return(new BookingResponse(errorMessage));
            }
            try
            {
                await _bookingRepository.Create(booking);

                await _context.SaveChangesAsync();

                var showNames = _aadService.IsAdmin() || _viewRepository.GetShowNamesById(viewId);
                return(new BookingResponse(BookingMapper.Map(booking, showNames)));
            }
            catch (Exception ex)
            {
                string errorMessage = $"An error occured when creating the booking: {ex.Message}";
                Log.Error <string>(ex, "An error occured when creating the booking: {booking}", JsonSerializer.Serialize(booking));
                return(new BookingResponse(errorMessage));
            }
        }
示例#3
0
        public ActionResult SetRoom(int id)
        {
            var roomtype  = _roomrepo.FindById(id);
            var employees = _userManager.GetUsersInRoleAsync("Employee").Result;

            foreach (var emp in employees)
            {
                if (_bookrepo.CheckAllocation(id, emp.Id))
                {
                    continue;
                }
                var allocation = new BookingViewModel
                {
                    // BookingDate is the same as DateCreated
                    BookingDate  = DateTime.Now,
                    EmployeeId   = emp.Id,
                    RoomTypeId   = id,
                    NumberOfDays = roomtype.DefaultDays,
                    Period       = DateTime.Now.Year
                };
                var roomallocation = _mapper.Map <Booking>(allocation);
                _bookrepo.Create(roomallocation);
            }
            return(RedirectToAction(nameof(Index)));
        }
示例#4
0
        public BookingDTO Create([FromBody] BookingDTO booking)
        {
            Booking    Booking    = _repos.Create(booking);
            BookingDTO BookingDTO = _mapper.Map <Booking, BookingDTO> (Booking);

            return(BookingDTO);
        }
示例#5
0
        public async Task <ActionResult <BookingListDTO> > Post(int StoreId)
        {
            var result = await _repository.Create(StoreId);

            if (result == null)
            {
                return(BadRequest());
            }
            return(result);
        }
 public IActionResult Create(Booking st)
 {
     if (ModelState.IsValid)
     {
         bookingRepository.Create(st);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
        public async Task <bool> Handle(CreateBookingCommand request, CancellationToken cancellationToken)
        {
            var connectedUser = _userRepo.FindByName(request.User).Result;
            var flight        = _flightRepo.Get(request.FlightId).Result;

            if (connectedUser == null || flight == null)
            {
                // TODO : Exception
            }
            await _bookingRepo.Create(new Booking()
            {
                User = connectedUser, Flight = flight, Date = DateTime.Now, Count = request.Count
            });

            return(true);
        }
示例#8
0
        public async Task <IActionResult> Book(BookPackageViewModel vm)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Content("Login required!"));
            }
            else if (User.IsInRole("Customer"))
            {
                if (ModelState.IsValid)
                {
                    Package         currentPackage  = _packageRepo.GetSingle(p => p.PackageId == vm.PackageId);
                    Provider        currentProvider = _providerRepo.GetSingle(p => p.ProviderId == currentPackage.ProviderId);
                    ApplicationUser currentUser     = await _userManagerService.FindByNameAsync(User.Identity.Name);

                    Customer currentCustomer = _customerRepo.GetSingle(c => c.UserId == currentUser.Id);

                    Booking actualBooking = new Booking
                    {
                        CustomerId          = currentCustomer.CustomerId,
                        PackageId           = currentPackage.PackageId,
                        DateMade            = DateTime.Now,
                        CompanyName         = currentProvider.DisplayName,
                        PackageName         = currentPackage.Name,
                        DateFor             = vm.DateFor,
                        NumberOfPeople      = vm.NumberOfPeople,
                        SpecialRequirements = vm.SpecialRequirements,
                        Price  = currentPackage.Price,
                        IsPaid = false
                    };

                    _bookingRepo.Create(actualBooking);

                    string emailContent = "Dear " + currentCustomer.FirstName + ",\n\nThank you for your order with Grande Travel.\n" +
                                          "Please don't hesitate to check your booking details here:\n" +
                                          "http://localhost:5000/Packages/BookedPackages [Login required]\n\n" +
                                          "Kind Regards,\nGrande Travel";

                    await _emailService.SendEmailAsync(currentUser.Email, "Grande Travel - Do not reply", emailContent);

                    return(RedirectToAction("BookedPackages", "Packages"));
                }
                return(View(vm));
            }
            return(Content("Must be a Customer to book a package! Nice try though! ;)"));
        }
示例#9
0
        public async Task UpdateStatus(Guid id, BookingState newStatus, string declineReason)
        {
            var bookingRequest = await GetById(id);

            if (newStatus == BookingState.Approved)
            {
                var booking = BookingMapper.Map(bookingRequest);
                await _bookingRepository.Create(booking);
            }
            else
            {
                bookingRequest.DeclineReason = declineReason;
            }

            bookingRequest.Status = newStatus;

            _repository.Update(bookingRequest);
            await _context.SaveChangesAsync();
        }
        public void Create_InputBookingWithId0_SetBookingId1()
        {
            // Arrange
            int                expectedListCount = 1;
            var                context           = SqlLiteInMemoryContext();
            EFUnitOfWork       uow        = new EFUnitOfWork(context);
            IBookingRepository repository = uow.Bookings;

            Booking Booking = new Booking()
            {
                id = 1, firstname = "John", lastname = "Smith"
            };

            //Act
            repository.Create(Booking);
            uow.Save();
            var factListCount = context.Bookings.Count();

            // Assert
            Assert.Equal(expectedListCount, factListCount);
        }
        public async Task <IActionResult> CreateAsync(CreateBookingViewModel formulaire) //  Method(class nom de l'object)
        {
            // Post de booking -> model qui contient les valuers du formuliare
            //

            {
                if (ModelState.IsValid)                                                  // si model est valide alors
                {
                    var LoggedIn    = User.IsInRole("Admin, User");                      // false / true
                    var currentuser = await _userManager.GetUserAsync(HttpContext.User); // class ApplicationUser -> USER QUI EST logged in.

                    //if (LoggedIn) // if statement sont des check sur valuers (pas sur properties
                    // -> Gargae 1 et garage 3 => admin de garage 1 , rajouter une voiture dans garage 1 , que il est bien admin de garage 1.
                    // -> naviger vers http/local/garage2


                    BookingVehicule nouveaubookingquidoitallerdansbanquededonnees = new BookingVehicule
                    {
                        ApplicationUserId = currentuser.Id, // Class -> template (only properties) Class avec values -> object de la classe -> currentuser est un object de la classe applicationuser.
                        CarId             = formulaire.CarId,
                        StartDate         = formulaire.StartDate,
                        EndDate           = formulaire.EndDate,
                        CreateBy          = currentuser.Email,
                    };



                    var response = _bookingRepository.Create(nouveaubookingquidoitallerdansbanquededonnees);

                    if (response != null && response.BookingId != 0)
                    {
                        return(RedirectToAction("details", "Booking", new { id = nouveaubookingquidoitallerdansbanquededonnees.BookingId }));
                    }

                    return(View("NotAuthorized"));
                }
                return(View(formulaire));
            }
        }
        public async Task <BookingViewModel> Create(BookingViewModel model)
        {
            var booking = _mapper.Map <BookingViewModel, BookingModel>(model);
            var hasUser = await _userRepository.AnyAsync(w => w.Id == booking.UserId);

            var isReserved = await _bookingRepository
                             .AnyAsync(b => ((b.Start <= booking.End && b.End >= booking.End) ||
                                             (b.Start <= booking.Start && b.End >= booking.Start) ||
                                             (booking.Start <b.Start && booking.End> b.End)) &&
                                       booking.ApartmentId == b.ApartmentId);

            if (!hasUser)
            {
                throw new Exception("User not found");
            }
            if (isReserved)
            {
                throw new Exception("Apartment is reserved");
            }

            await _bookingRepository.Create(booking);

            return(_mapper.Map <BookingModel, BookingViewModel>(booking));
        }
示例#13
0
        public async Task <ActionResult <Booking> > PostBooking([FromBody] Booking booking)
        {
            var newBooking = await _bookingRepository.Create(booking);

            return(CreatedAtAction(nameof(GetBookings), new { id = newBooking.BookingID }, newBooking));
        }
示例#14
0
 public async Task <bool> Add([FromBody] Booking booking)
 {
     return(await bookingRepository.Create(booking));
 }