public CustomerDomainModel FindById(int id) { var customerDomainModel = new CustomerDomainModel(); var customerDataModel = _customerRepository.FindById(id); customerDomainModel.Id = customerDataModel.Id; customerDomainModel.AgentId = customerDataModel.AgentId; customerDomainModel.Guid = customerDataModel.Guid; customerDomainModel.IsActive = customerDataModel.IsActive; customerDomainModel.Balance = customerDataModel.Balance; customerDomainModel.Age = customerDataModel.Age; customerDomainModel.EyeColor = customerDataModel.EyeColor; customerDomainModel.Name = new CustomerDomainModel.CustomerName() { First = customerDataModel.Name.First, Last = customerDataModel.Name.Last }; customerDomainModel.Company = customerDataModel.Company; customerDomainModel.Email = customerDataModel.Email; customerDomainModel.Phone = customerDataModel.Phone; customerDomainModel.Address = customerDataModel.Address; customerDomainModel.Registered = customerDataModel.Registered; customerDomainModel.Latitude = customerDataModel.Latitude; customerDomainModel.Longitude = customerDataModel.Longitude; customerDomainModel.Tags = customerDataModel.Tags; return(customerDomainModel); }
public bool CreateCustomerPhoneInfo(string phoneNumber, string customerId, out string message) { message = "操作失败,请与管理员联系"; if (string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(customerId)) { message = "参数错误,联系号码或客户ID不能为空"; return(false); } CustomerDomainModel customerInfo = CustomerInfoService.Instance.GetCustomerDomainModelById(customerId, false); if (customerInfo == null) { message = "操作失败,不存在的客户ID"; return(false); } CustomerPhoneInfoModel phoneInfo = new CustomerPhoneInfoModel(); phoneInfo.PhoneNumber = phoneNumber; phoneInfo.CustomerId = customerId; return(CreateCustomerPhoneInfo(phoneInfo, out message)); }
public async Task Insert_Should_Create_Customer() { // Arrange IUnitOfWork unitOfWork = new UnitOfWork(_fixture.Context); var customerRepository = new TrackableRepository <Customer>(_fixture.Context); var customerDomainService = new CustomerDomainService(customerRepository, _mapper); const string customerId = "COMP1"; const string companyName = "Company 1"; var customer = new CustomerDomainModel { CustomerId = customerId, CompanyName = companyName }; // Act customerDomainService.Insert(customer); var savedChanges = await unitOfWork.SaveChangesAsync(); // Assert Assert.Equal(1, savedChanges); var newCustomer = await customerRepository.FindAsync(customerId); Assert.Equal(newCustomer.CustomerId, customerId); Assert.Equal(newCustomer.CompanyName, companyName); }
public void Add(CustomerDomainModel customerDomainModel) { var customerDataModel = new CustomerDataModel() { Id = customerDomainModel.Id, AgentId = customerDomainModel.AgentId, Guid = customerDomainModel.Guid, IsActive = customerDomainModel.IsActive, Balance = customerDomainModel.Balance, Age = customerDomainModel.Age, EyeColor = customerDomainModel.EyeColor, Name = new CustomerDataModel.CustomerName() { First = customerDomainModel.Name.First, Last = customerDomainModel.Name.Last }, Company = customerDomainModel.Company, Email = customerDomainModel.Email, Phone = customerDomainModel.Phone, Address = customerDomainModel.Address, Registered = customerDomainModel.Registered, Latitude = customerDomainModel.Latitude, Longitude = customerDomainModel.Longitude, Tags = customerDomainModel.Tags }; _customerRepository.Add(customerDataModel); }
public async Task <string> AddUpdateUser(CustomerVM customerVM) { CustomerDomainModel customerDM = new CustomerDomainModel(); AutoMapper.Mapper.Map(customerVM, customerDM); return(await customerBusiness.AddUpdateCustomer(customerDM)); }
public async Task <CustomerToReturnVM> GetCustomerById(int id) { CustomerToReturnVM customerToReturnVM = new CustomerToReturnVM(); CustomerDomainModel customerDomainModel = await customerBusiness.GetCustomerById(id); AutoMapper.Mapper.Map(customerDomainModel, customerToReturnVM); return(customerToReturnVM); }
public bool CreateContactInfo(CustomerContactInfoModel contactInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; CustomerDomainModel customer = CustomerInfoService.Instance.GetCustomerDomainModelById(contactInfo.CustomerId, false); if (customer == null) { message = "操作失败,目标客户不存在"; return(false); } if (contactInfo != null) { contactInfo.ContactId = GetGuid(); PhoneLocationInfoModel loc = PhoneLocationInfoService.Instance.GetLocationInfo(contactInfo.CustomerPhone, false); if (loc != null) { contactInfo.FromCityId = loc.ChinaId; contactInfo.FromCityName = loc.City; } try { BeginTransaction(); if (Create(contactInfo) == 1) { if (contactInfo.CustomerPhone != "") { CustomerPhoneInfoModel phoneInfo = new CustomerPhoneInfoModel(); phoneInfo.CustomerId = contactInfo.CustomerId; phoneInfo.PhoneNumber = contactInfo.CustomerPhone; if (!CustomerPhoneInfoService.Instance.CreateCustomerPhoneInfo(phoneInfo, out message)) { RollbackTransaction(); message = "添加客户联系号码失败"; return(false); } } CommitTransaction(); result = true; message = "成功创建客户联系记录"; CustomerInfoService.Instance.GetCustomerDomainModelById(contactInfo.CustomerId, true); } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("建客户联系记录异常", ex); throw ex; } } return(result); }
private void AssertValidCustomerAndAddress(Customer customer, CustomerDomainModel newCustomer) { Assert.Equal(customer.CustomerEmail, newCustomer.CustomerEmail); Assert.Equal(customer.CustomerName, newCustomer.CustomerName); Assert.Equal(customer.Address.City, newCustomer.Address.City); Assert.Equal(customer.Address.Country, newCustomer.Address.Country); Assert.Equal(customer.Address.Line1, newCustomer.Address.Line1); Assert.Equal(customer.Address.PostalCode, newCustomer.Address.PostalCode); Assert.Equal(customer.Address.State, newCustomer.Address.State); }
public void Patch(int id, JsonPatchDocument <CustomerDomainModel> customerDomainModel) { var customerToPatchDataModel = _customerRepository.FindById(id); var customerToPatchDomainModel = new CustomerDomainModel(); customerToPatchDomainModel.Id = customerToPatchDataModel.Id; customerToPatchDomainModel.AgentId = customerToPatchDataModel.AgentId; customerToPatchDomainModel.Guid = customerToPatchDataModel.Guid; customerToPatchDomainModel.IsActive = customerToPatchDataModel.IsActive; customerToPatchDomainModel.Balance = customerToPatchDataModel.Balance; customerToPatchDomainModel.Age = customerToPatchDataModel.Age; customerToPatchDomainModel.EyeColor = customerToPatchDataModel.EyeColor; customerToPatchDomainModel.Name = new CustomerDomainModel.CustomerName() { First = customerToPatchDataModel.Name.First, Last = customerToPatchDataModel.Name.Last }; customerToPatchDomainModel.Company = customerToPatchDataModel.Company; customerToPatchDomainModel.Email = customerToPatchDataModel.Email; customerToPatchDomainModel.Phone = customerToPatchDataModel.Phone; customerToPatchDomainModel.Address = customerToPatchDataModel.Address; customerToPatchDomainModel.Registered = customerToPatchDataModel.Registered; customerToPatchDomainModel.Latitude = customerToPatchDataModel.Latitude; customerToPatchDomainModel.Longitude = customerToPatchDataModel.Longitude; customerToPatchDomainModel.Tags = customerToPatchDataModel.Tags; customerDomainModel.ApplyTo(customerToPatchDomainModel); var patchedCustomerDataModel = new CustomerDataModel() { Id = customerToPatchDomainModel.Id, AgentId = customerToPatchDomainModel.AgentId, Guid = customerToPatchDomainModel.Guid, IsActive = customerToPatchDomainModel.IsActive, Balance = customerToPatchDomainModel.Balance, Age = customerToPatchDomainModel.Age, EyeColor = customerToPatchDomainModel.EyeColor, Name = new CustomerDataModel.CustomerName() { First = customerToPatchDomainModel.Name.First, Last = customerToPatchDomainModel.Name.Last }, Company = customerToPatchDomainModel.Company, Email = customerToPatchDomainModel.Email, Phone = customerToPatchDomainModel.Phone, Address = customerToPatchDomainModel.Address, Registered = customerToPatchDomainModel.Registered, Latitude = customerToPatchDomainModel.Latitude, Longitude = customerToPatchDomainModel.Longitude, Tags = customerToPatchDomainModel.Tags }; _customerRepository.Update(patchedCustomerDataModel); }
private void AddCustomer(CustomerDomainModel item) { using (var ctx = new BankAccountDbContext()) { ctx.CustomerSet.Add(new CustomerEntity { AggregateId = item.Id, Version = item.Version, CustomerState = State.Open }); ctx.SaveChanges(); } }
/// <summary> /// Inserts a customer into the CRM. If the customer's address is valid, their address is also inserted. /// Otherwise only the customer is inserted /// </summary> /// <param name="customer"></param> /// <returns></returns> public async Task <bool> UpsertCustomerAsync(CustomerDomainModel customer) { var validAddress = await _addressService.ValidAddressAsync(customer.Address); if (!validAddress) { customer.Address = null; } await _crmRepository.UpsertCustomer(customer); return(validAddress); }
public async Task <CustomerDomainModel> GetCustomerById(int id) { CustomerDomainModel customer = new CustomerDomainModel(); var model = await customerRepository.SingleOrDefault(c => c.cus_id == id); if (model != null) { customer.cus_id = model.cus_id; customer.name = model.name; customer.contact = model.contact; } return(customer); }
private void UpdateCustomer(CustomerDomainModel item) { using (var ctx = new BankAccountDbContext()) { var entity = ctx.CustomerSet.SingleOrDefault(b => b.AggregateId == item.Id); if (entity == null) { throw new AggregateNotFoundException("Bank account"); } entity.Version = item.Version; entity.CustomerState = item.State; ctx.Entry(entity).State = EntityState.Modified; ctx.SaveChanges(); } }
public void Save(CustomerDomainModel item) { CustomerEntity entity; using (var ctx = new BankAccountDbContext()) { entity = ctx.CustomerSet.SingleOrDefault(b => b.AggregateId == item.Id); } if (entity == null) { this.AddCustomer(item); } else { this.UpdateCustomer(item); } }
public static CustomerEntity ToCustomerEntity(this CustomerDomainModel customerDomainModel) { var customerId = Guid.NewGuid(); var entity = new CustomerEntity { CustomerEmail = customerDomainModel.CustomerEmail, CustomerName = customerDomainModel.CustomerName, CustomerId = customerId }; var address = customerDomainModel.Address?.ToAddressEntity(); if (address != null) { entity.Address.Add(address); } return(entity); }
public async Task FindAsync_Should_Return_DomainModel(bool useKey) { // Arrange var customerRepository = new TrackableRepository <Customer>(_fixture.Context); var customerService = new CustomerDomainService(customerRepository, _mapper); var customerDomainModel = new CustomerDomainModel(); // Act if (useKey) { customerDomainModel = await customerService.FindAsync("ALFKI"); } else { customerDomainModel = await customerService.FindAsync(new object[] { "ALFKI" }); } // Assert Assert.Equal("ALFKI", customerDomainModel.CustomerId); Assert.NotNull(customerDomainModel); }
public async Task Update_Should_Update_Customer() { // Arrange IUnitOfWork unitOfWork = new UnitOfWork(_fixture.Context); var customerRepository = new TrackableRepository <Customer>(_fixture.Context); var customerDomainService = new CustomerDomainService(customerRepository, _mapper); const string customerId = "BERGS"; const string companyName = "Eastern Connection 1"; var data = await customerRepository.FindAsync(customerId); customerRepository.Detach(data); var customerDomainModel = new CustomerDomainModel { CustomerId = data.CustomerId, CompanyName = companyName, ContactName = data.ContactName, ContactTitle = data.ContactTitle, Address = data.Address, City = data.City, Region = data.Region, PostalCode = data.PostalCode, Country = data.Country, Phone = data.Phone, Fax = data.Fax }; // Act customerDomainService.Update(customerDomainModel); var savedChanges = await unitOfWork.SaveChangesAsync(); // Assert Assert.Equal(1, savedChanges); var updatedCustomer = await customerRepository.FindAsync(customerId); Assert.Equal(data.Address, updatedCustomer.Address); Assert.Equal(customerDomainModel.CompanyName, companyName); }
public async Task <string> AddUpdateCustomer(CustomerDomainModel customer) { string status = ""; if (customer.cus_id > 0) { tblCustomer customerToUpdate = await customerRepository.SingleOrDefault(c => c.cus_id == customer.cus_id); if (customerToUpdate != null) { customerToUpdate.name = customer.name; customerToUpdate.contact = customer.contact; await customerRepository.Update(customerToUpdate); status = "updated"; } } else { tblCustomer customerToAdd = new tblCustomer(); tblCustomer cust = new tblCustomer(); cust = await customerRepository.SingleOrDefault(c => c.contact == customer.contact); if (cust != null) { } else { customerToAdd.name = customer.name; customerToAdd.contact = customer.contact; customerToAdd.date = DateTime.Now; await customerRepository.Insert(customerToAdd); status = "added"; } } return(status); }
public void Update(CustomerDomainModel customerDomainModel) { _customerManager.Update(customerDomainModel); }
// 在此添加你的代码... public bool UpdateCreditcardInfo(CustomerCreditcardInfoModel creditInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; if (creditInfo == null) { message = "参数错误,请与管理员联系"; return(false); } CustomerDomainModel customer = CustomerInfoService.Instance.GetCustomerDomainModelById(creditInfo.CustomerId, false); if (customer == null) { message = "参数错误,不存在的客户ID,请与管理员联系"; return(false); } CustomerSecurityInfoDomainModel securityInfo = CustomerInfoService.Instance.GetCustomerSecurityInfo(creditInfo.IvrDataId, false); if (securityInfo == null) { message = "未能从IVR系统获取客户输入的敏感信息,请与管理员联系"; return(false); } creditInfo.CreditcardNumber = securityInfo.CreditCardNumber; creditInfo.IdcardNumber = securityInfo.IdCardNumber; creditInfo.Period = securityInfo.PeriodCode; creditInfo.SecurityCode = securityInfo.SecurityCode; if (creditInfo.CreditcardNumber.Length > 6) { BankcardTypeInfoModel bankCardTypeModel = BankcardTypeInfoService.Instance.GetBankCardInfoByBinCode(creditInfo.CreditcardNumber.Substring(0, 6)); if (bankCardTypeModel != null) { creditInfo.CardType = bankCardTypeModel.CardType; creditInfo.CardLevel = bankCardTypeModel.CardLevel; creditInfo.CardBrand = bankCardTypeModel.CardBrand; creditInfo.CanbeStage = (bankCardTypeModel.BankcardEnumValue == "FEB39D81-26EC-4A20-97F2-F148FDC87AFD") ? 0 : 1; } } if (string.IsNullOrEmpty(creditInfo.CreditcardNumber)) { message = "未能从IVR系统获取客户输入的敏感信息,请检查输入"; return(false); } try { BeginTransaction(); if (Update(creditInfo) == 1) { CommitTransaction(); message = "成功更新客户持卡信息"; result = true; CustomerInfoService.Instance.GetCustomerDomainModelById(creditInfo.CustomerId, true); } else { RollbackTransaction(); message = "更新客户持卡信息失败,请与管理员联系"; result = false; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("更新客户持卡信息异常", ex); throw ex; } return(result); }
/// <summary> /// Fake CRM Stub. Inserts customer /// </summary> /// <param name="customerDomainModel"></param> /// <returns></returns> public async Task UpsertCustomer(CustomerDomainModel customerDomainModel) { await _dbContext.AddAsync(customerDomainModel.ToCustomerEntity()); await _dbContext.SaveChangesAsync(); }
private void AssertValidCustomerWithInValidAddress(Customer customer, CustomerDomainModel newCustomer) { Assert.Equal(customer.CustomerEmail, newCustomer.CustomerEmail); Assert.Equal(customer.CustomerName, newCustomer.CustomerName); Assert.Null(newCustomer.Address); }
public void Add(CustomerDomainModel customerDomainModel) { _customerManager.Add(customerDomainModel); }
// 在此添加你的代码... public bool CreateCustomerDeliveryInfo(CustomerDeliveryInfoModel deliveryInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; if (deliveryInfo == null) { message = "参数错误,请与管理员联系"; return(false); } if (string.IsNullOrEmpty(deliveryInfo.Consignee)) { message = "收货人姓名不能为空,请检查输入"; return(false); } if (string.IsNullOrEmpty(deliveryInfo.ConsigneePhone)) { message = "收货人电话不能为空,请检查输入"; return(false); } CustomerDomainModel customer = CustomerInfoService.Instance.GetCustomerDomainModelById(deliveryInfo.CustomerId, false); if (customer == null) { message = "参数错误,不存在的客户ID,请与管理员联系"; return(false); } deliveryInfo.DeliveryId = GetGuid(); deliveryInfo.StatusCode = 0; try { BeginTransaction(); if (Create(deliveryInfo) == 1) { CommitTransaction(); message = "成功创建客户配送信息"; result = true; CustomerInfoService.Instance.GetCustomerDomainModelById(deliveryInfo.CustomerId, true); } else { RollbackTransaction(); message = "创建客户配送信息失败,请与管理员联系"; result = false; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("创建客户配送信息异常", ex); throw ex; } return(result); }
public bool UpdateCustomerPhoneInfo(string oldphoneNumber, string phoneNumber, string customerId, out string message) { bool result = false; if (string.IsNullOrEmpty(oldphoneNumber)) { if (CreateCustomerPhoneInfo(phoneNumber, customerId, out message) == true) { message = "成功更新客户联系号码"; result = true; return(result); } else { message = "更新客户联系号码参数错误,请与管理员联系"; return(false); } } message = "操作失败,请与管理员联系"; if (string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(customerId)) { message = "参数错误,联系号码或客户ID不能为空"; return(false); } CustomerDomainModel customerInfo = CustomerInfoService.Instance.GetCustomerDomainModelById(customerId, false); if (customerInfo == null) { message = "操作失败,不存在的客户ID"; return(false); } CustomerPhoneInfoModel phoneInfo = new CustomerPhoneInfoModel(); phoneInfo.PhoneNumber = phoneNumber; phoneInfo.CustomerId = customerId; string checkExistsSQL = "SELECT * FROM customer_phone_info WHERE phone_number = $oldphoneNumber$ AND customer_id = $CustomerId$"; ParameterCollection pc = new ParameterCollection(); pc.Add("CustomerId", phoneInfo.CustomerId); pc.Add("oldphoneNumber", oldphoneNumber); string phoneid = ExecuteScalar(checkExistsSQL, pc).ToString(); if (string.IsNullOrEmpty(phoneid)) { message = "更新客户联系号码参数错误,请与管理员联系"; return(false); } phoneInfo.PhoneId = phoneid; phoneInfo.CallStatus = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("号码状态", false).GetCustomDataValueDomainByDataValue("正常").ValueId; phoneInfo.PhoneType = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("号码类型", false).GetCustomDataValueDomainByDataValue("其他电话").ValueId; phoneInfo.Status = 0; PhoneLocationInfoModel loc = PhoneLocationInfoService.Instance.GetLocationInfo(phoneInfo.PhoneNumber, false); if (loc != null) { phoneInfo.FromCityId = loc.ChinaId.ToString(); phoneInfo.FromCityName = loc.City; } else { message = "填写号码无法判断归属地,请检查。如果是固定电话,请加上区号"; //return false; } if (Update(phoneInfo) == 1) { message = "成功更新客户联系号码"; return(true); } return(result); }