예제 #1
0
        public async Task <bool> CreateAsync(ReservationModel value, int OwnerUserId)
        {
            IEnumerable <User> InvitedUsers = await _userRepository.FindRangeAsync(value.InvitedUsersIds);

            Room room = await _roomRepository.FindAsync(value.RoomId);

            User OwnerUser = await _userRepository.FindAsync(OwnerUserId);

            if (!InvitedUsers.Any() ||
                InvitedUsers.Count() != value.InvitedUsersIds.Count() ||
                room == null ||
                !await _reservationRepository.CheckIfCanReservAsync(value.DateFrom, value.DateTo, room) ||
                value.DateFrom > value.DateTo)
            {
                return(false);
            }

            await _reservationRepository.CreateAsync(value, room, OwnerUser, InvitedUsers);

            return(true);
        }