コード例 #1
0
        public ActionResult Create()
        {
            ViewModels.Leads.CreateLeadViewModel            viewModel          = new ViewModels.Leads.CreateLeadViewModel();
            List <ViewModels.Leads.LeadStatusViewModel>     leadStatusList     = new List <ViewModels.Leads.LeadStatusViewModel>();
            List <ViewModels.Leads.LeadSourceViewModel>     leadSourceList     = new List <ViewModels.Leads.LeadSourceViewModel>();
            List <ViewModels.Leads.LeadSourceTypeViewModel> leadSourceTypeList = new List <ViewModels.Leads.LeadSourceTypeViewModel>();

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                // Leads are external to organization
                viewModel.Contact = new ViewModels.Contacts.ContactViewModel()
                {
                    IsOurEmployee = false
                };

                Data.Leads.LeadStatus.List(conn, false).ForEach(x =>
                {
                    leadStatusList.Add(Mapper.Map <ViewModels.Leads.LeadStatusViewModel>(x));
                });

                Data.Leads.LeadSource.List(conn, false).ForEach(x =>
                {
                    leadSourceList.Add(Mapper.Map <ViewModels.Leads.LeadSourceViewModel>(x));
                });

                Data.Leads.LeadSourceType.List(conn, false).ForEach(x =>
                {
                    leadSourceTypeList.Add(Mapper.Map <ViewModels.Leads.LeadSourceTypeViewModel>(x));
                });
            }

            ViewBag.LeadStatusList     = leadStatusList;
            ViewBag.LeadSourceList     = leadSourceList;
            ViewBag.LeadSourceTypeList = leadSourceTypeList;

            return(View());
        }
コード例 #2
0
        public ActionResult Create(ViewModels.Leads.CreateLeadViewModel viewModel)
        {
            Common.Models.Account.Users currentUser;
            Common.Models.Leads.Lead    model;

            using (Data.Transaction trans = Data.Transaction.Create(true))
            {
                try
                {
                    currentUser = Data.Account.Users.Get(trans, User.Identity.Name);

                    // Existing v. New checks
                    if (viewModel.ExistingContactId.HasValue)
                    {
                        viewModel.Contact.Id = viewModel.ExistingContactId;
                    }
                    if (viewModel.ExistingSourceId.HasValue)
                    {
                        viewModel.Source.Id = viewModel.ExistingSourceId;
                    }
                    if (viewModel.ExistingSourceContactId.HasValue)
                    {
                        viewModel.Source.Contact.Id = viewModel.ExistingSourceContactId;
                    }
                    if (viewModel.ExistingFeeToId.HasValue)
                    {
                        viewModel.Fee.To.Id = viewModel.ExistingFeeToId;
                    }

                    model = Mapper.Map <Common.Models.Leads.Lead>((ViewModels.Leads.LeadViewModel)viewModel);

                    if (!viewModel.ExistingContactId.HasValue)
                    {
                        model.Contact = Mapper.Map <Common.Models.Contacts.Contact>(viewModel.Contact);
                        model.Contact = Data.Contacts.Contact.Create(trans, model.Contact, currentUser);
                    }

                    if (!viewModel.ExistingSourceId.HasValue)
                    {
                        model.Source = Mapper.Map <Common.Models.Leads.LeadSource>(viewModel.Source);
                        model.Source = Data.Leads.LeadSource.Create(trans, model.Source, currentUser);
                    }

                    if (!viewModel.ExistingFeeToId.HasValue)
                    {
                        model.Fee = Mapper.Map <Common.Models.Leads.LeadFee>(viewModel.Fee);
                        model.Fee = Data.Leads.LeadFee.Create(trans, model.Fee, currentUser);
                    }

                    model = Data.Leads.Lead.Create(trans, model, currentUser);

                    trans.Commit();

                    return(RedirectToAction("Details", new { Id = model.Id.Value }));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(RedirectToAction("Create"));
                }
            }
        }