示例#1
0
        public Guid InsertOrUpdateAddressWithUserDto(UserModelUpdateDto user)
        {
            var addressExistsForUser = _unitOfWork.Addresses.FindAddressByUserId(user.Id);

            if (addressExistsForUser != null)
            {
                var validedForUpdate = ValidateUpdateAddressInsideDto(user, addressExistsForUser);

                if (VerifyAnyFieldFilled(validedForUpdate))
                {
                    return(UpdateAddress(validedForUpdate));
                }

                return(Guid.Empty);
            }

            var validedForInsert = ValidateInsertAddressInsideDto(user);

            if (VerifyAnyFieldFilled(validedForInsert))
            {
                return(AddAddress(validedForInsert));
            }

            return(Guid.Empty);
        }
示例#2
0
        private User UpdateAlteredUser(User old, UserModelUpdateDto alteredDto)
        {
            old.Name = !string.IsNullOrEmpty(alteredDto.Name)
                ? alteredDto.Name
                : old.Name;

            old.Email = !string.IsNullOrEmpty(alteredDto.Email)
                ? alteredDto.Email
                : old.Email;

            if (!string.IsNullOrEmpty(alteredDto.Password) && alteredDto.Password != old.Password)
            {
                var alteredDtoPasswordEncrypted = EncryptHelper.EncryptMD5(alteredDto.Password);

                if (alteredDtoPasswordEncrypted != old.Password)
                {
                    old.Password = alteredDtoPasswordEncrypted;
                }
            }


            old.Gender     = alteredDto.Gender;
            old.UpdateDate = DateTimeOffset.Now;

            return(old);
        }
示例#3
0
        public Guid UpdateUser(UserModelUpdateDto alteredUser)
        {
            if (alteredUser == null)
            {
                throw new Exception("Usuario invalido");
            }

            var validate = new UserModelUpdateDtoValidator().Validate(alteredUser);

            if (!validate.IsValid)
            {
                throw new Exception("Usuario invalido");
            }

            var oldUser = _unitOfWork.Users.Query(x => x.Id == alteredUser.Id);

            if (oldUser == null)
            {
                throw new Exception("Usuario invalido");
            }

            oldUser = UpdateAlteredUser(oldUser, alteredUser);

            _unitOfWork.Users.Update(oldUser);
            _unitOfWork.Commit();
            return(alteredUser.Id);
        }
示例#4
0
        private AddressModelCreateDto ValidateInsertAddressInsideDto(UserModelUpdateDto user)
        {
            AddressModelCreateDto addressDto = new AddressModelCreateDto();

            addressDto.Street       = !string.IsNullOrEmpty(user.Street) ? user.Street : string.Empty;
            addressDto.Number       = !string.IsNullOrEmpty(user.Number) ? user.Number : string.Empty;
            addressDto.Neighborhood = !string.IsNullOrEmpty(user.Neighborhood) ? user.Neighborhood : string.Empty;
            addressDto.Complement   = !string.IsNullOrEmpty(user.Complement) ? user.Complement : string.Empty;
            addressDto.City         = !string.IsNullOrEmpty(user.City) ? user.City : string.Empty;
            addressDto.UserId       = user.Id;

            return(addressDto);
        }
示例#5
0
        public OperationResponse <Guid> UpdateUser([FromBody] UserModelUpdateDto user)
        {
            OperationResponse <Guid> response = new OperationResponse <Guid>();

            try
            {
                var result = _serviceUser.UpdateUser(user);
                _serviceAddress.InsertOrUpdateAddressWithUserDto(user);

                response.Data = result;
                response.Messages.Add(new OperationMessage {
                    Description = UserResource.User_Success_Update, Type = OperationMessageTypes.Success
                });
            }
            catch (Exception ex)
            {
                _serviceLog.Add(LogHelper.GenerateLog(ControllerContext, "UpdateUser", UserResource.User_Error_Update, CurrentUser.Email, ex));
                response.Messages.Add(new OperationMessage {
                    Description = UserResource.User_Error_Update + " : " + ex.Message, Type = OperationMessageTypes.Error
                });
            }
            return(response);
        }