コード例 #1
0
ファイル: CRMLeadService.cs プロジェクト: xprasoulas/grid
        public bool Delete(int id)
        {
            // Check whether lead exists or not ?
            var crmLead = _crmLeadRepository.Get(id);

            if (crmLead != null)
            {
                // Delete all Lead Activities
                var activities = _crmLeadActivityRepository.GetAllBy(m => m.CRMLeadId == id).ToList();
                foreach (var activity in activities)
                {
                    _crmLeadActivityRepository.Delete(activity);
                }

                // Delete all Lead Technology Maps
                var technologies = _crmLeadTechnologyMapRepository.GetAllBy(m => m.LeadId == id).ToList();
                foreach (var technology in technologies)
                {
                    _crmLeadTechnologyMapRepository.Delete(technology);
                }

                _unitOfWork.Commit();

                _crmLeadRepository.Delete(id);
                _unitOfWork.Commit();

                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: CRMLeadsController.cs プロジェクト: xprasoulas/grid
        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));
        }