Ejemplo n.º 1
0
        public ActionResult ConvertLead(long Id = 0)
        {
            ViewBag.SuccessMessage = "";

            ConvertLeadFormModel convertlead = new ConvertLeadFormModel();

            convertlead = getLeadDropDownValues(convertlead);

            if (Id != 0)
            {
                convertlead.LeadID = Id;
            }

            return View("ConvertLead", convertlead);
        }
Ejemplo n.º 2
0
        public ActionResult ConvertLead(ConvertLeadFormModel convertlead)
        {
            try
            {
                // Get Lead

                Lead lead = leadService.GetLead(convertlead.LeadID);

                // Creation of Account

                Account account = new Account()
                {
                    AccountName = convertlead.AccountName,
                    WebSite = lead.WebSite,
                    Email = lead.Email,
                    Phone = lead.Phone,
                    Fax = lead.Fax,
                    BillingAddress = lead.Street,
                    BillingCity = lead.City,
                    BillingState = lead.State,
                    BillingCountry = lead.Country,
                    BillingPoBox = lead.POBox,
                    AssignedTo = convertlead.AssignedTo,
                    CreatedOn = DateTime.Now,
                    ModifiedOn = DateTime.Now,
                    CreatedBy = Session["UserID"].ToString(),
                    ModifiedBy = Session["UserID"].ToString(),
                    AssignedToUserGroup = "user"
                };

                accountService.CreateAccount(account);

                // Creation of Contact

                Contact contact = new Contact()
                {
                    FirstName = lead.FirstName,
                    LastName = lead.LastName,
                    LeadSource = lead.LeadSource,
                    HomePhone = lead.Phone,
                    Email = lead.Email,
                    OfficePhone = lead.Phone,
                    Fax = lead.Fax,
                    MailingStreet = lead.Street,
                    MailingCity = lead.City,
                    MailingState = lead.State,
                    MailingCountry = lead.Country,
                    MailingPostalCode = lead.POBox,
                    AssignedTo = convertlead.AssignedTo,
                    CreatedOn = DateTime.Now,
                    ModifiedOn = DateTime.Now,
                    CreatedBy = Session["UserID"].ToString(),
                    ModifiedBy = Session["UserID"].ToString(),
                    AssignedToUserGroup = "user"
                };

                contactService.CreateContact(contact);

                // Creation of Potential
                if (!(convertlead.DoNotPotentialCreate))
                {
                    Potential potential = new Potential()
                    {
                        LeadSource = lead.LeadSource,
                        PotentialName = convertlead.PotentialName,
                        ExpectedCloseDate = convertlead.PotentialCloseDate,
                        Amount = convertlead.PotentialAmount.ToString(),
                        SalesStage = ((SalesStageEnum)convertlead.PotentialSalesStage).ToString(),
                        AssignedTo = convertlead.AssignedTo,
                        CreatedOn = DateTime.Now,
                        ModifiedOn = DateTime.Now,
                        CreatedBy = Session["UserID"].ToString(),
                        ModifiedBy = Session["UserID"].ToString(),
                        AssignedToUserGroup = "user"
                    };

                    potentialService.CreatePotential(potential);

                    return RedirectToAction("List", "Potential");
                }

                return RedirectToAction("List", "Account");
            }
            catch (Exception ex)
            {
                ViewBag.successMessage = "";
                ViewBag.errorMessage = string.Format("Error in Convert Lead Save : {0}", ex.Message);
            }

            return View("ConvertLead", convertlead);
        }
Ejemplo n.º 3
0
        private ConvertLeadFormModel getLeadDropDownValues(ConvertLeadFormModel convertlead)
        {
            var users = userService.GetUsers();

            if (convertlead.AssignedTo == 0)
            {
                convertlead.AssignedTo = users.FirstOrDefault(s => s.UserID == Session["UserID"].ToString()).ID;
            }

            List<SelectListItem> items = new List<SelectListItem>();
            items.AddRange(users.OrderBy(user => user.Name)
             .Select(user =>
            new SelectListItem
            {
                Selected = (user.ID == convertlead.AssignedTo),
                Text = user.Name,
                Value = user.ID.ToString()
            }));

            convertlead.GrpUserList = items;

            IEnumerable<SalesStageEnum> statustypes = Enum.GetValues(typeof(SalesStageEnum))
                                                               .Cast<SalesStageEnum>();

            convertlead.SalesStageList = from src in statustypes
                                         select new SelectListItem
                                         {
                                             Text = src.ToString(),
                                             Value = ((int)src).ToString()
                                         };
            return convertlead;
        }