public async Task <RoomDTO> CreateRoom(RoomCreateDTO roomCreateDTO, int userID) { ValidationResults result = ModelValidator.IsValid(roomCreateDTO); if (!result.Successed) { throw ValidationExceptionBuilder.BuildValidationException(result); } var hotel = context.Hotels.Get(roomCreateDTO.HotelId); if (hotel == null) { throw new NotFoundException("No such hotel"); } if (hotel.HotelAdminId != userID) { throw new PermissionException(); } var isExistsWithNumber = hotel.Rooms.Where(r => r.NumberInHotel == roomCreateDTO.NumberInHotel).Count() != 0; if (isExistsWithNumber) { throw new ValidationException("Hotel room with such number already exists"); } var room = roomCreateDTO.ToRoom(); context.Rooms.Create(room); await context.SaveAsync(); return(room.ToRoomDTO()); }