public ActionResult Edit(CRMContact cRMContact) { if (ModelState.IsValid) { var selectedContact = _crmContactRepository.GetBy(l => l.Id == cRMContact.Id); if (selectedContact != null) { selectedContact.ParentAccountId = cRMContact.ParentAccountId; selectedContact.Person.FirstName = cRMContact.Person.FirstName; selectedContact.Person.LastName = cRMContact.Person.LastName; selectedContact.Person.Gender = cRMContact.Person.Gender; selectedContact.Person.Email = cRMContact.Person.Email; selectedContact.Person.Organization = cRMContact.Person.Organization; selectedContact.Person.Designation = cRMContact.Person.Designation; selectedContact.Person.PhoneNo = cRMContact.Person.PhoneNo; selectedContact.Person.SecondaryEmail = cRMContact.Person.SecondaryEmail; selectedContact.Person.OfficePhone = cRMContact.Person.OfficePhone; selectedContact.Person.Website = cRMContact.Person.Website; selectedContact.Person.Skype = cRMContact.Person.Skype; selectedContact.Person.Facebook = cRMContact.Person.Facebook; selectedContact.Person.Twitter = cRMContact.Person.Twitter; selectedContact.Person.GooglePlus = cRMContact.Person.GooglePlus; selectedContact.Person.LinkedIn = cRMContact.Person.LinkedIn; selectedContact.Person.City = cRMContact.Person.City; selectedContact.Person.Country = cRMContact.Person.Country; selectedContact.Person.Address = cRMContact.Person.Address; selectedContact.Person.CommunicationAddress = cRMContact.Person.CommunicationAddress; selectedContact.Person.DateOfBirth = cRMContact.Person.DateOfBirth; selectedContact.Expertise = cRMContact.Expertise; selectedContact.Comments = cRMContact.Comments; selectedContact.UpdatedByUserId = WebUser.Id; _crmContactRepository.Update(selectedContact); _unitOfWork.Commit(); return(RedirectToAction("Index")); } } return(View(cRMContact)); }
public ActionResult Update(CRMContactModel cRMContact) { ApiResult <CRMContact> apiResult; if (ModelState.IsValid) { if (cRMContact.Id > 0) { apiResult = TryExecute(() => { var person = _personRepository.GetBy(l => l.Id == cRMContact.PersonId); if (person != null) { person.Id = cRMContact.PersonId; person.FirstName = cRMContact.FirstName; person.LastName = cRMContact.LastName; person.Gender = cRMContact.Gender; person.Email = cRMContact.Email; person.Organization = cRMContact.Organization; person.Designation = cRMContact.Designation; person.PhoneNo = cRMContact.PhoneNo; person.SecondaryEmail = cRMContact.SecondaryEmail; person.OfficePhone = cRMContact.OfficePhone; person.Website = cRMContact.Website; person.Skype = cRMContact.Skype; person.Facebook = cRMContact.Facebook; person.Twitter = cRMContact.Twitter; person.GooglePlus = cRMContact.GooglePlus; person.LinkedIn = cRMContact.LinkedIn; person.City = cRMContact.City; person.Country = cRMContact.Country; person.Address = cRMContact.Address; person.CommunicationAddress = cRMContact.CommunicationAddress; person.DateOfBirth = cRMContact.DateOfBirth; _personRepository.Update(person); _unitOfWork.Commit(); } var selectedContact = _crmContactRepository.GetBy(l => l.Id == cRMContact.Id); if (selectedContact != null) { selectedContact.ParentAccountId = cRMContact.ParentAccountId; selectedContact.Expertise = cRMContact.Expertise; selectedContact.Comments = cRMContact.Comments; selectedContact.UpdatedByUserId = WebUser.Id; _crmContactRepository.Update(selectedContact); _unitOfWork.Commit(); } return(selectedContact); }, "Contact updated sucessfully"); } else { apiResult = TryExecute(() => { var newPerson = new Person { FirstName = cRMContact.FirstName, LastName = cRMContact.LastName, Gender = cRMContact.Gender, Email = cRMContact.Email, Organization = cRMContact.Organization, Designation = cRMContact.Designation, PhoneNo = cRMContact.PhoneNo, SecondaryEmail = cRMContact.SecondaryEmail, OfficePhone = cRMContact.OfficePhone, Website = cRMContact.Website, Skype = cRMContact.Skype, Facebook = cRMContact.Facebook, Twitter = cRMContact.Twitter, GooglePlus = cRMContact.GooglePlus, LinkedIn = cRMContact.LinkedIn, City = cRMContact.City, Country = cRMContact.Country, Address = cRMContact.Address, CommunicationAddress = cRMContact.CommunicationAddress, DateOfBirth = cRMContact.DateOfBirth, }; var person = _personRepository.Create(newPerson); var newContact = new CRMContact { PersonId = person.Id, ParentAccountId = cRMContact.ParentAccountId, Expertise = cRMContact.Expertise, Comments = cRMContact.Comments, CreatedByUserId = WebUser.Id }; var contact = _crmContactRepository.Create(newContact); _unitOfWork.Commit(); return(newContact); }, "Contact created sucessfully"); } } else { apiResult = ApiResultFromModelErrors <CRMContact>(); } return(Json(apiResult, JsonRequestBehavior.AllowGet)); }