public void UpdateBlock(BlockModifyingDTO block, Guid BlockID) { var oldType = _blockingRepository.GetBlockById(BlockID); if (oldType == null) { throw new NotFoundException("There is no block with that ID"); } var newType = mapper.Map <Block>(block); newType.BlockID = BlockID; newType.BlockDate = DateTime.Now; if (newType.blockerID == newType.blockedID) { throw new ErrorOccurException("Error! You can not block yourself!"); } if (!_blockingRepository.CheckDoIFollowUser(newType.blockerID, newType.blockedID)) { throw new FollowingException("You dont follow user with that ID, so you can not block him!"); } if (_blockingRepository.CheckDidIAlreadyBlockUser(newType.blockerID, newType.blockedID)) { throw new BlockingException("You already blocked this user, you are not following him!"); } try { mapper.Map(newType, oldType); _blockingRepository.SaveChanges(); } catch (Exception ex) { throw new ErrorOccurException("Error updating block: " + ex.Message); } }
public IActionResult UpdateRatingType([FromHeader] string key, [FromBody] BlockModifyingDTO updated, Guid BlockID) { if (!_authService.Authorize(key)) { return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!")); } var newType = mapper.Map <Block>(updated); try { _blockingService.UpdateBlock(updated, BlockID); var res = mapper.Map <Block>(newType); res.BlockID = BlockID; return(Ok(res)); } catch (Exception ex) { logger.LogError(ex, "Error updating block: " + ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }