- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Edit(ContactDetailViewModel model)
- {
- if (ModelState.IsValid)
- {
- model.Id = _Login.GetCurrentUserCustomer().Id;
- using (var dbContextScope = _dbContextScopeFactory.Create())
- {
- Contact contact = model;
- contact.ContactAttributes = new List
(); - var user = _Login.GetCurrentUser();
- if(model.Attributes != null)
- {
- foreach (var item in model.Attributes)
- {
- if (item.AddressValue != null)
- {
- ContactAttribute attribute = new ContactAttribute()
- {
- AttributeValue = item.AddressValue,
- Code = item.AddressElement,
- Contact = contact//,
- };
- _ContactRepo.UpdateContactAttribute(attribute, user);
- contact.ContactAttributes.Add(attribute);
- }
- }
- }
- try
- {
- _ContactRepo.UpdateContact(contact, user);
- }
- catch (RMException rme)
- {
- rme.Log();
- ModelState.AddModelError("", "Updating contact failed. Please check your values and try again.");
- return PartialView(model);
- }
- dbContextScope.SaveChanges();
- }
- }
- else
- {
- return PartialView(model);
- }
- return RedirectToAction("Index", "Contact");
- }
- public ContactAttribute UpdateContactAttribute(ContactAttribute attribute, User user)
- {
- var dbAttribute = DbContext.ContactAttributes.Find(attribute.ContactId);
- dbAttribute.AttributeValue = attribute.AttributeValue;
- dbAttribute.Code = attribute.Code;
- UpdateWithUser(dbAttribute, user.UserId, "ContactRepo.UpdateContactAttribute");
- return dbAttribute;
- }


Salman BegRank #284 · 8.8K reputationPosted Apr 10, 2020, 9:21 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Apr 10, 2020, 9:36 PM EDT