Beispiel #1
0
        public ActionResult Edit(int id)
        {
            var cRMLead = _crmLeadRepository.Get(id);

            if (cRMLead == null)
            {
                return(HttpNotFound());
            }

            // Check whether i have access to this Lead details
            var hasAccess = cRMLead.AssignedToUserId == WebUser.Id || DoIHaveCRMManageAccess();

            if (!hasAccess)
            {
                return(RedirectToAction("NotAuthorized", "Error", new { area = "" }));
            }

            var mappedTechnologies = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == cRMLead.Id).Select(m => m.TechnologyId).ToList();

            ViewBag.Technologies     = new MultiSelectList(_technologyRepository.GetAll(), "Id", "Title", mappedTechnologies);
            ViewBag.AssignedToUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", cRMLead.AssignedToUserId);
            ViewBag.LeadSourceId     = new SelectList(_crmLeadSourceRepository.GetAll(), "Id", "Title", cRMLead.LeadSourceId);
            ViewBag.CategoryId       = new SelectList(_crmLeadCategoryRepository.GetAll(), "Id", "Title", cRMLead.CategoryId);
            ViewBag.LeadSourceUserId = new SelectList(_userRepository.GetAll("Person"), "Id", "Person.Name", cRMLead.LeadSourceUserId);
            ViewBag.LeadStatusId     = new SelectList(_crmLeadStatusRepository.GetAll(), "Id", "Name", cRMLead.LeadStatusId);

            var vm = new EditCRMLeadViewModel(cRMLead);

            return(View(vm));
        }
Beispiel #2
0
        public ActionResult Edit(EditCRMLeadViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var selectedLead = _crmLeadRepository.GetBy(l => l.Id == vm.Id);

                if (selectedLead != null)
                {
                    // Check whether i have access to this Lead details
                    var hasAccess = selectedLead.AssignedToUserId == WebUser.Id || DoIHaveCRMManageAccess();
                    if (!hasAccess)
                    {
                        return(RedirectToAction("NotAuthorized", "Error", new { area = "" }));
                    }

                    selectedLead.AssignedToUserId = vm.AssignedToUserId;
                    selectedLead.LeadSourceId     = vm.LeadSourceId;
                    selectedLead.LeadSourceUserId = vm.LeadSourceUserId;
                    selectedLead.CategoryId       = vm.CategoryId;

                    selectedLead.Person.FirstName            = vm.Person.FirstName;
                    selectedLead.Person.LastName             = vm.Person.LastName;
                    selectedLead.Person.Gender               = vm.Person.Gender;
                    selectedLead.Person.Email                = vm.Person.Email;
                    selectedLead.Person.Organization         = vm.Person.Organization;
                    selectedLead.Person.Designation          = vm.Person.Designation;
                    selectedLead.Person.PhoneNo              = vm.Person.PhoneNo;
                    selectedLead.Person.SecondaryEmail       = vm.Person.SecondaryEmail;
                    selectedLead.Person.OfficePhone          = vm.Person.OfficePhone;
                    selectedLead.Person.Website              = vm.Person.Website;
                    selectedLead.Person.Skype                = vm.Person.Skype;
                    selectedLead.Person.Facebook             = vm.Person.Facebook;
                    selectedLead.Person.Twitter              = vm.Person.Twitter;
                    selectedLead.Person.GooglePlus           = vm.Person.GooglePlus;
                    selectedLead.Person.LinkedIn             = vm.Person.LinkedIn;
                    selectedLead.Person.City                 = vm.Person.City;
                    selectedLead.Person.Country              = vm.Person.Country;
                    selectedLead.Person.Address              = vm.Person.Address;
                    selectedLead.Person.CommunicationAddress = vm.Person.CommunicationAddress;
                    selectedLead.Person.DateOfBirth          = vm.Person.DateOfBirth;

                    selectedLead.Expertise   = vm.Expertise;
                    selectedLead.Description = vm.Description;
                    selectedLead.RecievedOn  = vm.RecievedOn;

                    selectedLead.UpdatedByUserId = WebUser.Id;

                    _crmLeadRepository.Update(selectedLead);
                    _unitOfWork.Commit();


                    // Remove the existing mapped Technologies
                    var existingMaps = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == selectedLead.Id);
                    foreach (var map in existingMaps)
                    {
                        _crmLeadTechnologyMapRepository.Delete(map);
                    }

                    _unitOfWork.Commit();

                    if (vm.TechnologyIds != null)
                    {
                        // Map the New Technologies
                        foreach (var technologyId in vm.TechnologyIds)
                        {
                            var newMap = new CRMLeadTechnologyMap
                            {
                                LeadId       = vm.Id,
                                TechnologyId = technologyId
                            };

                            _crmLeadTechnologyMapRepository.Create(newMap);
                        }

                        _unitOfWork.Commit();
                    }

                    return(RedirectToAction("Index"));
                }
            }

            return(View(vm));
        }