示例#1
0
        public override async Task <RequestModel> Create([FromBody] UserDTO entity)
        {
            if (entity == null)
            {
                return(await base.Create(entity));
            }

            if (string.IsNullOrEmpty(entity.Password))
            {
                return(await RequestModel.ErrorRequestAsync("The Password field is required.", 400));
            }

            entity.Password = Encryptor.SH1Hash(entity.Password);

            return(await base.Create(entity));
        }
示例#2
0
        public override async Task <RequestModel> Update([FromBody] UserDTO entity)
        {
            if (entity == null)
            {
                return(await RequestModel.ErrorRequestAsync("User can not be null"));
            }

            User oldUser = await _repository.GetEntityByID(entity.Id);

            if (oldUser == null)
            {
                return(await RequestModel.NotFoundAsync());
            }

            var oldPassword = oldUser.HashPassword;
            var oldName     = oldUser.Name;

            _mapper.Map(entity, oldUser);

            if (string.IsNullOrEmpty(entity.Password) || Encryptor.SH1Hash(entity.Password) == oldPassword)
            {
                oldUser.HashPassword = oldPassword;
            }
            else
            {
                oldUser.HashPassword = Encryptor.SH1Hash(entity.Password);
            }

            await _repository.UpdateEntity(oldUser);

            if (oldName != entity.Name)
            {
                var nameUpdated = new UserNameUpdatedEvent()
                {
                    UserId = entity.Id, OldName = oldName, NewName = entity.Name
                };
                _eventBus.Publish(nameUpdated);
            }

            return(await RequestModel.SuccessAsync());
        }
示例#3
0
 public override async Task <RequestModel> Update([FromBody] TransactionDTO entity)
 {
     return(await RequestModel.ErrorRequestAsync("We will not support updating transaction's information", 501));
 }