/// <summary> /// To the view model. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public static ContactRelationshipViewModel ToViewModel(this ContactRelationshipModel entity) { if (entity == null) { return(null); } var model = new ContactRelationshipViewModel { ContactRelationshipTypeID = entity.ContactRelationshipTypeID, ContactID = entity.ContactID, ParentContactID = entity.ParentContactID, RelationshipTypeID = entity.RelationshipTypeID, RelationshipGroupID = entity.RelationshipGroupID, IsPolicyHolder = entity.IsPolicyHolder, OtherRelationship = entity.OtherRelationship, EffectiveDate = entity.EffectiveDate, ExpirationDate = entity.ExpirationDate, IsActive = entity.IsActive, ModifiedBy = entity.ModifiedBy, ModifiedOn = entity.ModifiedOn, LivingWithClientStatus = entity.LivingWithClientStatus, IsCollateral = entity.IsCollateral }; return(model); }
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 Response <ContactRelationshipViewModel> UpdateContactRelationship(ContactRelationshipViewModel contactRelationship) { return(_contactRelationshipRepository.UpdateContactRelationship(new List <ContactRelationshipViewModel> { contactRelationship })); }