public async Task HandleAsync(ChangePasswordCommand command) { var customerDomain = _mapper.Map <Customer>(command.ComandData); var customer = await _customerReadRepository.Get(command.ComandData.TenantId); if (customer == null) { await _customerWriteRepository.Add(customerDomain); } var user = await _userReadRepository.GetByUsername(command.ComandData.Data.Username); var userDomain = new User { Id = user == null?Guid.NewGuid() : user.Id, CustomerId = command.ComandData.TenantId, Username = command.ComandData.Data.Username, RoleId = (int)Common.Enums.Roles.Local, Password = MD5.CreateMD5(command.ComandData.Data.Password) }; if (user == null) { await _userWriteRepository.Add(userDomain); } else { await _userWriteRepository.Update(userDomain); } }
public async Task HandleAsync(ChangeMarginCommand command) { var customer = await _customerReadRepository.Get(command.ComandData.TenantId); if (customer == null) { customer = new Domain.Customers.Customer { Id = command.ComandData.TenantId, CreateDate = DateTime.Now, Margin = command.ComandData.Data.Margin }; await _customerWriteRepository.Add(customer); } else { customer.Margin = command.ComandData.Data.Margin; await _customerWriteRepository.Update(customer); } }
public async Task <GetCustomerModel> HandleAsync(GetCustomerFromMsGraf query) { var customer = await _cspClient.GetCustomerAsync(query.TenantId.ToString()); var customerDb = await _customerReadRepository.Get(query.TenantId); var user = await _userReadRepository.GetFirstByCustomerId(query.TenantId); return(new GetCustomerModel { Domain = customer?.Domain, Address = customer?.Address, PhoneNumber = customer?.PhoneNumber, City = customer?.City, Country = customer?.Country, PostalCode = customer?.PostalCode, Name = customer?.Name, Margin = customerDb?.Margin, Email = user?.Username }); }