Esempio n. 1
0
        public async Task <Block> AddAsync(BlockPostDto entity)
        {
            BlockPostDtoValidator validator = new BlockPostDtoValidator();
            ValidationResult      results   = validator.Validate(entity);

            if (!results.IsValid)
            {
                throw new ValidationException("BlockPostDTO", string.Join(". ", results.Errors));
            }

            var user2Exists = await userService.GetByIdAsync(entity.User2ID);

            if (user2Exists == null)
            {
                throw new BadRequestException("The user can't be blocked because he doesn't exist.");
            }

            entity.Date = DateTime.Now;

            return(await userRoleRepository.AddAsync(mapper.Map <Block>(entity)));
        }
        public async Task <IActionResult> AddNewBlock([FromBody] BlockPostDto blockPostDto)
        {
            var blockResp = await blockService.AddAsync(blockPostDto);

            return(CreatedAtAction("GetClient", new { user1Id = blockResp.User1ID, user2Id = blockResp.User2ID }, mapper.Map <BlockResponseDto>(blockResp)));
        }