public async Task <RequestDto> GetAsync(Guid id, ICollection <Claim> roles) { string itemId = IdExtensions.GetStringId(id); var itemDbo = await _repository.GetAsync(itemId); var itemDto = _mapper.Map <Request, RequestDto>(itemDbo); var isAdmin = IsRoleAdmin(roles); if (isAdmin) { return(itemDto); } else { List <string> requestStatuses = GetRequestStatuses(roles, actions.Get); if (requestStatuses.Count > 0) { var isAllowedItem = DoesItemMatchesStatus(itemDto, requestStatuses); if (isAllowedItem) { return(itemDto); } } throw new ForbiddenOperationRequestException(_messageMissingRole); } }
public async Task <TEntityDto> GetAsync(TId id) { string itemId = IdExtensions.GetStringId(id); var itemDbo = await _repository.GetAsync(itemId); var itemDto = _mapper.Map <TEntityDbo, TEntityDto>(itemDbo); return(itemDto); }
public async Task DeleteAsync(TId id) { string itemId = IdExtensions.GetStringId(id); var itemDbo = await _repository.GetAsync(itemId); Require.Objects.NotNull <NotFoundException>( itemDbo, () => $"Record with id: {id} does not exist"); Require.Booleans.IsFalse <ForbiddenOperationRequestException>( itemDbo.IsDeleted, $"You try remove the record that was already removed"); if (IsHasDeletableInterface(itemDbo)) { Require.Booleans.IsTrue <ForbiddenOperationRequestException>( itemDbo.IsDeletable, $"This record shoul not be removed"); } itemDbo.IsDeleted = true; await _repository.UpdateAsync(itemDbo); }