public ActionResult SaveCustomerContact(string keyValue, CustomerContactEntity entity) { try { #region 新增客户 if (string.IsNullOrWhiteSpace(keyValue)) { customercontactbll.SaveForm(keyValue, entity); } #endregion #region 更新客户信息 else { customercontactbll.SaveForm(keyValue, entity); } #endregion return(Success("成功")); } catch (Exception ex) { return(Error(ex.Message)); } }
public void AddToModel_NullCustomerProfileModelThrows_Test() { // init vars var source = new CustomerContactEntity(); CustomerProfileModel model = null; const string expectedParamName = nameof(model); // test target month TestAddToModelNullParameters(source, model, expectedParamName); }
public async Task GetCustomerProfileAsync_ValidBpNumber_ReturnsCustomerProfile() { // Arrange var user = TestHelper.PaDev1; var logic = CreateCustomerLogic(); mockCustomerRepository.Setup(cr => cr.GetCustomerAsync(It.IsAny <long>())) .Returns((long bpId) => { var customerEntity = new CustomerEntity { BusinessPartnerId = user.BpNumber, FullName = "JENNIFER L POWERS", FirstName = "JENNIFER", LastName = "POWERS" }; return(Task.FromResult(customerEntity)); }); mockCustomerRepository.Setup(cr => cr.GetCustomerContactAsync(It.IsAny <long>())) .Returns((long bpId) => { var customerContactEntity = new CustomerContactEntity { Email = user.Email, MailingAddress = user.Address, Phones = new Dictionary <string, PhoneDefinedType> { { "cell", new PhoneDefinedType { Number = user.Phones[0].Number, Extension = user.Phones[0].Extension } }, { "work", new PhoneDefinedType { Number = user.Phones[1].Number, Extension = user.Phones[1].Extension } } } }; return(Task.FromResult(customerContactEntity)); }); // Act var response = await logic.GetCustomerProfileAsync(user.BpNumber); // Assert response.ShouldNotBeNull(); response.ShouldBeOfType <CustomerProfileModel>(); response.MailingAddress.AddressLine1.ShouldBe(user.Address.AddressLine1); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, CustomerContactEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
private static List <Phone> GetPhones(CustomerContactEntity source) { List <Phone> phones = new List <Phone>(); foreach (KeyValuePair <string, PhoneDefinedType> entry in source.Phones) { phones.Add(new Phone { Type = entry.Key.ToEnum <PhoneType>(), Number = entry.Value.Number, Extension = entry.Value.Extension }); } return(phones); }
public ActionResult InitEditContactRelationship(string jsonData) { Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit ContactRelationship").Add("JsonContactRelationship", jsonData).ToInputLogString()); try { _commonFacade = new CommonFacade(); _customerFacade = new CustomerFacade(); var contactRelationVM = JsonConvert.DeserializeObject <ContactRelationshipViewModel>(jsonData); if (contactRelationVM.ListIndex != null) { CustomerContactEntity selected = contactRelationVM.ContactRelationshipList[contactRelationVM.ListIndex.Value]; contactRelationVM.AccountId = selected.AccountId; contactRelationVM.RelationshipId = selected.RelationshipId; contactRelationVM.Product = selected.Product; } if (contactRelationVM.CustomerId.HasValue) { var listAccount = _customerFacade.GetAccountByCustomerId(contactRelationVM.CustomerId.Value); TempData["AccountList"] = listAccount; // keep AccountList contactRelationVM.AccountList = new SelectList((IEnumerable)listAccount.Select(x => new { key = x.AccountId, value = x.ProductAndAccountNoDisplay }).ToDictionary(t => t.key, t => t.value), "Key", "Value", string.Empty); } // Get SelectList var lstRelationship = _commonFacade.GetRelationshipSelectList(); TempData["RelationshipList"] = lstRelationship; // Keep RelationshipList contactRelationVM.RelationshipList = new SelectList((IEnumerable)lstRelationship, "Key", "Value", string.Empty); return(PartialView("~/Views/Contact/_EditContactRelationship.cshtml", contactRelationVM)); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit ContactRelationship").Add("Error Message", ex.Message).ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }
private void TestAddToModelNullParameters(CustomerContactEntity source, CustomerProfileModel model, string expectedParamName) { try { //Act source.AddToModel(model); //Assert Assert.Fail("The expected ArgumentNullException was not thrown."); } catch (ArgumentNullException ex) { Console.WriteLine(ex); //Assert expectedParamName.ShouldBe(ex.ParamName); } }
public void AddToModel_Test() { //Arrange var user = TestHelper.PaDev1; var customerContactEntity = new CustomerContactEntity { Email = user.Email, MailingAddress = user.Address, Phones = new Dictionary <string, PhoneDefinedType> { { "cell", new PhoneDefinedType { Number = user.Phones[0].Number, Extension = user.Phones[0].Extension } }, { "work", new PhoneDefinedType { Number = user.Phones[1].Number, Extension = user.Phones[1].Extension } } } }; CustomerProfileModel model = new CustomerProfileModel(); // Act customerContactEntity.AddToModel(model); model.EmailAddress.ShouldBe(customerContactEntity.Email); model.MailingAddress.ShouldBe(customerContactEntity.MailingAddress); var firstPhone = model.Phones.FirstOrDefault(); firstPhone.ShouldNotBeNull(); firstPhone.Number.ShouldBe(customerContactEntity.Phones["cell"].Number); firstPhone.Extension.ShouldBe(customerContactEntity.Phones["cell"].Extension); var lastPhone = model.Phones.Last(); lastPhone.Number.ShouldBe(customerContactEntity.Phones["work"].Number); lastPhone.Extension.ShouldBe(customerContactEntity.Phones["work"].Extension); }
/// <summary> /// Augment the CustomerProfileModel object with some of the CustomerContactEntity fields /// </summary> /// <param name="source"></param> /// <param name="model"></param> public static void AddToModel(this CustomerContactEntity source, CustomerProfileModel model) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } model.EmailAddress = source.Email; model.MailingAddress = source.MailingAddress; List <Phone> phones = GetPhones(source); model.Phones = phones; model.PrimaryPhone = (model.Phones.Any()) ? model.Phones.First().Type : model.PrimaryPhone; }
public ActionResult SaveContactForm(string keyValue, CustomerContactEntity entity) { customercontactbll.SaveForm(keyValue, entity); return(Success("操作成功。")); }
public ActionResult EditContactRelationship(ContactRelationshipViewModel contactRelationVM) { Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit ContactRelationship").Add("AccountId", contactRelationVM.AccountId) .Add("RelationshipId", contactRelationVM.RelationshipId).ToInputLogString()); try { CustomerContactEntity custContact = contactRelationVM.ListIndex != null ? contactRelationVM.ContactRelationshipList[contactRelationVM.ListIndex.Value] : new CustomerContactEntity(); if (ModelState.IsValid) { // Check Duplicate var objCheckDup = contactRelationVM.ContactRelationshipList.FirstOrDefault( x => x.AccountId == contactRelationVM.AccountId); if (objCheckDup != null && custContact.AccountId != objCheckDup.AccountId) { ModelState.AddModelError("AccountId", Resource.Error_SaveDuplicateContact); goto Outer; } custContact.AccountId = contactRelationVM.AccountId; custContact.RelationshipId = contactRelationVM.RelationshipId; if (TempData["AccountList"] != null) { var lstAccount = (List <AccountEntity>)TempData["AccountList"]; var objAccount = lstAccount.FirstOrDefault(x => x.AccountId == contactRelationVM.AccountId); custContact.AccountNo = objAccount.AccountNo; custContact.Product = objAccount.Product; custContact.AccountDesc = objAccount.AccountDesc; TempData["AccountList"] = lstAccount; // keep AccountList } if (TempData["RelationshipList"] != null) { var lstRelationship = (IDictionary <string, string>)TempData["RelationshipList"]; var objRelationship = lstRelationship.FirstOrDefault(x => x.Key == contactRelationVM.RelationshipId.ToString(CultureInfo.InvariantCulture)); custContact.RelationshipName = objRelationship.Value; TempData["RelationshipList"] = lstRelationship; // keep RelationshipList } if (contactRelationVM.ListIndex == null) { custContact.CustomerId = contactRelationVM.CustomerId; custContact.IsEdit = true; #region "Customer Name" var custInfoVM = this.MappingCustomerInfoView(custContact.CustomerId.Value); custContact.CustomerFullNameThaiEng = custInfoVM.FirstNameThaiEng + " " + custInfoVM.LastNameThaiEng; #endregion contactRelationVM.ContactRelationshipList.Add(custContact); } return(Json(new { Valid = true, Data = contactRelationVM.ContactRelationshipList })); } Outer: return(Json(new { Valid = false, Error = string.Empty, Errors = GetModelValidationErrors() })); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit ContactRelationship").Add("Error Message", ex.Message).ToFailLogString()); return(Json(new { Valid = false, Error = Resource.Error_System, Errors = string.Empty })); } }
public HttpResponseMessage SaveCustomerContact(string ticket, string keyValue, CustomerContactEntity entity) { UserEntity userEntity = GetCurrent(ticket); if (userEntity != null) { try { #region 新增客户 if (string.IsNullOrWhiteSpace(keyValue)) { entity.CustomerContactId = Guid.NewGuid().ToString(); entity.EnabledMark = 1; entity.CreateUserId = userEntity.UserId; entity.CreateUserName = userEntity.RealName; entity.CreateDate = DateTime.Now; customercontactbll.AppSaveForm(keyValue, entity); } #endregion #region 更新客户信息 else { entity.CustomerId = keyValue; entity.ModifyUserId = userEntity.UserId; entity.ModifyUserName = userEntity.RealName; entity.ModifyDate = DateTime.Now; customercontactbll.AppSaveForm(keyValue, entity); } #endregion return(Success("成功")); } catch (Exception ex) { return(Error(ex.Message)); } } else { return(Error("票据验证失败")); } }