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.");
            }
        }
Beispiel #2
0
        public async Task <SetDto> GetSingleAsync(Guid id)
        {
            var set = await _setRepository.GetSingleAsync(id);

            return(_mapper.Map <Set, SetDto>(set));
        }