public ActionResult InitEditCustomerContact(int?contactId = null, int?customerId = null) { Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit CustomerContact").Add("ContactId", contactId) .Add("CustomerId", customerId).ToInputLogString()); try { ContactEditViewModel contactEditVM = new ContactEditViewModel(); _customerFacade = new CustomerFacade(); if (contactId.HasValue && customerId.HasValue) { var contactEntity = _customerFacade.GetContactByID(contactId.Value); contactEditVM.ContactId = contactEntity.ContactId; contactEditVM.SubscriptType = contactEntity.SubscriptType != null?contactEntity.SubscriptType.SubscriptTypeId.ConvertToString() : string.Empty; contactEditVM.TitleThai = contactEntity.TitleThai != null?contactEntity.TitleThai.TitleId.ConvertToString() : string.Empty; contactEditVM.TitleEnglish = contactEntity.TitleEnglish != null?contactEntity.TitleEnglish.TitleId.ConvertToString() : string.Empty; contactEditVM.FirstNameThai = contactEntity.FirstNameThai; contactEditVM.LastNameThai = contactEntity.LastNameThai; contactEditVM.TitleEnglish = contactEntity.TitleEnglish != null?contactEntity.TitleEnglish.TitleId.ConvertToString() : string.Empty; contactEditVM.FirstNameEnglish = contactEntity.FirstNameEnglish; contactEditVM.LastNameEnglish = contactEntity.LastNameEnglish; contactEditVM.CardNo = contactEntity.CardNo; contactEditVM.BirthDate = contactEntity.BirthDateDisplay; contactEditVM.Email = contactEntity.Email; contactEditVM.Fax = contactEntity.Fax; #region "Phone" // Phone if (contactEntity.PhoneList != null) { if (contactEntity.PhoneList.Count > 0) { contactEditVM.PhoneType1 = contactEntity.PhoneList[0].PhoneTypeId.ConvertToString(); contactEditVM.PhoneNo1 = contactEntity.PhoneList[0].PhoneNo; } else { contactEditVM.PhoneType1 = string.Empty; contactEditVM.PhoneNo1 = string.Empty; } if (contactEntity.PhoneList.Count > 1) { contactEditVM.PhoneType2 = contactEntity.PhoneList[1].PhoneTypeId.ConvertToString(); contactEditVM.PhoneNo2 = contactEntity.PhoneList[1].PhoneNo; } else { contactEditVM.PhoneType2 = string.Empty; contactEditVM.PhoneNo2 = string.Empty; } if (contactEntity.PhoneList.Count > 2) { contactEditVM.PhoneType3 = contactEntity.PhoneList[2].PhoneTypeId.ConvertToString(); contactEditVM.PhoneNo3 = contactEntity.PhoneList[2].PhoneNo; } else { contactEditVM.PhoneType3 = string.Empty; contactEditVM.PhoneNo3 = string.Empty; } } #endregion contactEditVM.IsEdit = contactEntity.IsEdit.Value ? "1" : "0"; contactEditVM.CustomerId = customerId; // keep CustomerId contactEditVM.IsConfirm = "1"; var contactRelationships = _customerFacade.GetContactRelationshipList(contactId.Value, customerId.Value); contactEditVM.ContactRelationshipList = contactRelationships; contactEditVM.JsonContactRelationship = JsonConvert.SerializeObject(contactRelationships); } else { contactEditVM.IsEdit = "1"; // case New } // Get SelectList _commonFacade = new CommonFacade(); contactEditVM.SubscriptTypeList = new SelectList((IEnumerable)_commonFacade.GetSubscriptTypeSelectList(), "Key", "Value", string.Empty); contactEditVM.TitleThaiList = new SelectList((IEnumerable)_commonFacade.GetTitleThaiSelectList(), "Key", "Value", string.Empty); contactEditVM.TitleEnglishList = new SelectList((IEnumerable)_commonFacade.GetTitleEnglishSelectList(), "Key", "Value", string.Empty); contactEditVM.PhoneTypeList = new SelectList((IEnumerable)_commonFacade.GetPhoneTypeSelectList(), "Key", "Value", string.Empty); return(PartialView("~/Views/Contact/_EditCustomerContact.cshtml", contactEditVM)); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit CustomerContact").Add("Error Message", ex.Message).ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }