예제 #1
0
        public async Task <ResponseViewModel> UpdateAsync(UserUpdateRequestViewModel request)
        {
            using (_unitOfWork)
            {
                // Inicia a transação
                _unitOfWork.BeginTransaction();

                // Atualiza o Perfil
                ProfileUpdateCommand profileUpdateCommand  = new ProfileUpdateCommand(Convert.ToInt32(request.IdType), request.GuidProfile, request.Avatar, request.CpfCnpj, request.Address);
                ResponseCommand      profileUpdateResponse = await _mediator.Send(profileUpdateCommand, CancellationToken.None).ConfigureAwait(true);

                if (!profileUpdateResponse.Success)
                {
                    return(new ResponseViewModel(false, profileUpdateResponse.Object));
                }

                // Atualiza o Usuário
                UserUpdateCommand userUpdateCommand  = new UserUpdateCommand(request.GuidUser, request.Name, request.Email);
                ResponseCommand   userUpdateResponse = await _mediator.Send(userUpdateCommand, CancellationToken.None).ConfigureAwait(true);

                if (!userUpdateResponse.Success)
                {
                    return(new ResponseViewModel(false, userUpdateResponse.Object));
                }

                // Comita e Retorna
                _unitOfWork.CommitTransaction();
                return(new ResponseViewModel(true, "User updated"));
            }
        }
        public void Update(ProfileUpdateCommand request)
        {
            const string sql = "" +
                               " UPDATE FgjCqrsProfile " +
                               " SET IdType  = @IdType" +
                               "   , Avatar  = @Avatar" +
                               "   , CpfCnpj = @CpfCnpj" +
                               "   , Address = @Address" +
                               " WHERE Guid = @Guid";

            _unitOfWork.Connection.Execute(sql, request, _unitOfWork.Transaction);
        }