public ActionResult Create(CRMContact cRMContact) { if (ModelState.IsValid) { cRMContact.CreatedByUserId = WebUser.Id; _crmContactRepository.Create(cRMContact); _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)); }
public bool Convert(bool createAccount, bool createPotential, int id, int assignedToUserId, int?categoryId, double?expectedAmount, DateTime?expectedCloseDate, string description, DateTime?enquiredOn, int salesStage, int createdByUserId) { var selectedLead = _crmLeadRepository.GetBy(l => l.Id == id, "Person"); if (selectedLead != null) { CRMAccount selectedOrganization = null; if (createAccount) { // Create the Account First var organization = selectedLead.Person.Organization; if (!string.IsNullOrEmpty(organization)) { selectedOrganization = _crmAccountRepository.GetBy(a => a.Title == organization); if (selectedOrganization == null) { selectedOrganization = new CRMAccount { Title = organization, EmployeeCount = EmployeeCount.One2Ten, AssignedToEmployeeId = assignedToUserId, CreatedByUserId = createdByUserId }; _crmAccountRepository.Create(selectedOrganization); _unitOfWork.Commit(); } } } // Create Contact var contact = new CRMContact { PersonId = selectedLead.PersonId, CreatedByUserId = createdByUserId }; // Assign the account Id if (selectedOrganization != null) { contact.ParentAccountId = selectedOrganization.Id; } _crmContactRepository.Create(contact); _unitOfWork.Commit(); if (createPotential) { // Create the Potential var potential = new CRMPotential { CategoryId = categoryId, ExpectedAmount = expectedAmount, ExpectedCloseDate = expectedCloseDate, Description = description, EnquiredOn = enquiredOn, SalesStageId = salesStage, AssignedToUserId = assignedToUserId, ContactId = contact.Id, CreatedByUserId = createdByUserId }; _crmPotentialRepository.Create(potential); _unitOfWork.Commit(); // Move all Lead Technologies to Potential Technologies var technologies = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == selectedLead.Id).ToList(); foreach (var technology in technologies) { var technologyMap = new CRMPotentialTechnologyMap { PotentialId = potential.Id, TechnologyId = technology.TechnologyId }; _crmPotentialTechnologyMapRepository.Create(technologyMap); } // Move all Lead Activities to Potential Activities var activities = _crmLeadActivityRepository.GetAllBy(m => m.CRMLeadId == selectedLead.Id).ToList(); foreach (var activity in activities) { var potentialActivity = new CRMPotentialActivity { CRMPotentialId = potential.Id, Title = activity.Title, Comment = activity.Comment, CreatedOn = activity.CreatedOn, CreatedByUserId = createdByUserId }; _crmPotentialActivityRepository.Create(potentialActivity); } _unitOfWork.Commit(); } // Delete the Lead _crmLeadService.Delete(id); return(true); } return(false); }