Esempio n. 1
0
        public async Task CreateAsync(RentalDTO rental)
        {
            var rentalToCheck = await _rentalRepository.GetAsync(rental.Id);

            if (rentalToCheck != null)
            {
                throw new Exception($"Rental with id: {rental.Id} already exists.");
            }

            var rentalToAdd = CreateRentalFromDTO(rental);

            await _rentalRepository.AddAsync(rentalToAdd);

            await _rentalRepository.SaveAsync();
        }
Esempio n. 2
0
        public async Task Rent(Guid userId, Guid setId)
        {
            var user = await _userRepository.GetSingleAsync(userId);

            var set = await _setRepository.GetSingleAsync(setId);

            if (user == null || set == null)
            {
                throw new Exception("Given user or set is invalid. Cannot finish rent operation.");
            }
            else if (set.IsAvailable)
            {
                var rental = new Rental(RentalStatus.Borrowed, setId, userId, DateTime.UtcNow);
                await _rentalRepository.AddAsync(rental);

                set.IsAvailable = false;
            }
            else
            {
                throw new Exception("Given set is not available.");
            }
        }