public static UserBlackList ToUserBlackList(this UserBLCreateDTO userBLCreateDTO)
 {
     return(new UserBlackList()
     {
         GuestId = userBLCreateDTO.GuestId,
         Reason = userBLCreateDTO.Reason
     });
 }
        public async Task <UserBlackListDTO> CreateUserBlackList(UserBLCreateDTO userBLCreateDTO, int userId)
        {
            ValidationResults result = ModelValidator.IsValid(userBLCreateDTO);

            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(userBLCreateDTO.GuestId);

            if (guest == null)
            {
                throw new NotFoundException("No such user");
            }

            int hotelId   = hotelAdmin.Hotel.Id;
            var countInDB = context.UserBlackLists
                            .GetAll()
                            .Where(x => x.HotelId == hotelId &&
                                   x.GuestId == userBLCreateDTO.GuestId)
                            .Count();

            if (countInDB != 0)
            {
                throw new ValidationException("This user is already in a black list");
            }

            var blackList = userBLCreateDTO.ToUserBlackList();

            blackList.HotelId = hotelId;
            context.UserBlackLists.Create(blackList);
            await context.SaveAsync();

            return(blackList.ToUserBlackListDTO());
        }
 public async Task <UserBlackListDTO> CreateUserBlackList([FromBody] UserBLCreateDTO userBLCreateDTO)
 {
     return(await blackListService.CreateUserBlackList(userBLCreateDTO, User.ConvertToUserData().Id));
 }