public async Task <UserBlackListDTO> EditBlackList(UserBLEditDTO userBLEditDTO, int userId) { ValidationResults result = ModelValidator.IsValid(userBLEditDTO); if (!result.Successed) { throw ValidationExceptionBuilder.BuildValidationException(result); } HotelAdmin hotelAdmin = context.HotelAdmins.Get(userId); if (hotelAdmin == null) { throw new NotFoundException("No such hotel"); } Guest guest = context.Guests.Get(userBLEditDTO.GuestId); if (guest == null) { throw new NotFoundException("No such user"); } int hotelId = hotelAdmin.Hotel.Id; var userBlackList = context.UserBlackLists.GetAll() .Where(x => x.HotelId == hotelId && x.GuestId == userBLEditDTO.GuestId).FirstOrDefault(); if (userBlackList == null) { throw new NotFoundException("No such user in the hotel's black list"); } userBlackList.Reason = userBLEditDTO.Reason; context.UserBlackLists.Update(userBlackList); await context.SaveAsync(); return(userBlackList.ToUserBlackListDTO()); }
public async Task <UserBlackListDTO> EditBlackList(UserBLEditDTO userBLEditDTO) { return(await blackListService.EditBlackList(userBLEditDTO, User.ConvertToUserData().Id)); }