public static ShopperAddressVm ToVm(this ShopperAddress address) { return(new ShopperAddressVm { Id = address.Id, Address = address.Address, Name = address.Name, Type = address.Type }); }
public async Task <DefaultResult> Handle(CreateShopperAddressCommand command, CancellationToken cancellationToken) { var result = new DefaultResult(); await _shopperAddressRepository.AddAsync(ShopperAddress.New(command.SessionUser.Id, command.Type, command.Address, command.Name)); if (!await CommitAsync()) { return(null); } return(result); }
public async Task <SaveShopperResult> Handle(CreateShopperCommand command, CancellationToken cancellationToken) { var result = new SaveShopperResult(); if (await _userRepository.AnyAsync(x => x.Email.ToLower() == command.Email.ToLower())) { Notifications.Handle("E-mail em uso"); } if (await _shopperRepository.AnyAsync(x => x.Cpf.Number.Equals(command.Cpf.Number))) { Notifications.Handle("CPF em uso"); } if (Notifications.HasNotifications()) { return(null); } var user = User.New(command.Email, _passwordHasherService.Hash(command.Password), command.Name, EUserType.Shopper); command.Cpf.Type = EIdentiticationType.Cpf; var shopper = Shopper.New(user, command.Cpf); await _shopperRepository.AddAsync(shopper); if (!await CommitAsync()) { return(null); } await _shopperAddressRepository.AddAsync(ShopperAddress.New(shopper.Id, EAddressType.Home, command.Address, "registro")); if (!await CommitAsync()) { return(null); } result.Id = shopper.Id; return(result); }