Exemple #1
0
        public async Task <FriendResponse> Update(FriendDto friendDto)
        {
            Friend friend = _mapper.Map <FriendDto, Friend>(friendDto);

            ValidationResult result = new FriendValidator(_repositoryFriend).Validate(friend);

            if (!result.IsValid)
            {
                return(new FriendResponse(result));
            }

            await _repositoryFriend.Update(friend);

            return(new FriendResponse(_mapper.Map <Friend, FriendDto>(friend), new NotificacaoDto(NotificacaoDto.TipoMensagem.Sucesso, "Amigo atualizado com sucesso!")));
        }
Exemple #2
0
        public ServiceResult <Friend> Add(Friend friend)
        {
            var friends = GetCollectionInCache();

            var validator = new FriendValidator(friends);
            var results   = validator.Validate(friend);

            if (results.IsValid == false)
            {
                return(ServiceResult <Friend> .Fail(
                           ServiceResultFailReason.BusinessValidation,
                           results.Errors.Select(x => x.ErrorMessage).ToList()));
            }

            AddFriendInCache(friend);

            return(ServiceResult <Friend> .Success(friend));
        }