コード例 #1
0
        public async Task <SaveShopperResult> Handle(UpdateShopperCommand command, CancellationToken cancellationToken)
        {
            var result = new SaveShopperResult();

            var include = new IncludeHelper <Shopper>().Include(x => x.User).Includes;
            var shopper = await _shopperRepository.FindAsync(x => x.Id == command.SessionUser.Id, include);

            if (shopper == null)
            {
                Notifications.Handle("Usuario não é um comprador");
                return(null);
            }

            shopper.Update(command.Name);

            if (!string.IsNullOrEmpty(command.Password))
            {
                shopper.User.UpdatePass(_passwordHasherService.Hash(command.Password));
            }

            result.Id = shopper.Id;

            _shopperRepository.Modify(shopper);

            if (!await CommitAsync())
            {
                return(null);
            }

            return(result);
        }
コード例 #2
0
 public async Task <IActionResult> SelfUpdateShopper(UpdateShopperCommand command)
 {
     command.SessionUser = _sessionUser;
     return(CreateResponse(await _mediator.Send(command, CancellationToken.None)));
 }