Beispiel #1
0
        public ActionResult Create(long?regleadid, long?regopportunityid)
        {
            Common.Models.Account.Users currentUser;
            ViewModels.Activities.ActivityPhonecallViewModel           viewModel        = new ViewModels.Activities.ActivityPhonecallViewModel();
            List <ViewModels.Activities.ActivityDirectionViewModel>    directionList    = new List <ViewModels.Activities.ActivityDirectionViewModel>();
            List <ViewModels.Activities.ActivityStatusReasonViewModel> statusReasonList = new List <ViewModels.Activities.ActivityStatusReasonViewModel>();
            List <ViewModels.Activities.ActivityPriorityViewModel>     priorityList     = new List <ViewModels.Activities.ActivityPriorityViewModel>();

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                currentUser = Data.Account.Users.Get(User.Identity.Name, conn, false);

                Data.Activities.ActivityDirection.List(conn, false).ForEach(x =>
                {
                    ViewModels.Activities.ActivityDirectionViewModel vm = Mapper.Map <ViewModels.Activities.ActivityDirectionViewModel>(x);
                    directionList.Add(vm);
                    if (vm.Order == 1)
                    {
                        viewModel.Direction = vm;
                    }
                });

                Data.Activities.ActivityStatusReason.List(conn, false).ForEach(x =>
                {
                    ViewModels.Activities.ActivityStatusReasonViewModel vm = Mapper.Map <ViewModels.Activities.ActivityStatusReasonViewModel>(x);
                    statusReasonList.Add(vm);
                    if (vm.Order == 1)
                    {
                        viewModel.StatusReason = vm;
                    }
                });

                Data.Activities.ActivityPriority.List(conn, false).ForEach(x =>
                {
                    ViewModels.Activities.ActivityPriorityViewModel vm = Mapper.Map <ViewModels.Activities.ActivityPriorityViewModel>(x);
                    priorityList.Add(vm);
                    if (vm.Default.HasValue && vm.Default.Value)
                    {
                        viewModel.Priority = vm;
                    }
                });

                if (regleadid != null && regleadid.HasValue)
                {
                    viewModel.RegardingLead = new ViewModels.Activities.ActivityRegardingLeadViewModel()
                    {
                        Type = new ViewModels.Activities.ActivityRegardingTypeViewModel()
                        {
                            Id = 1
                        }
                    };

                    viewModel.RegardingLead.Lead         = Mapper.Map <ViewModels.Leads.LeadViewModel>(Data.Leads.Lead.Get(regleadid.Value, conn, false));
                    viewModel.RegardingLead.Lead.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(viewModel.RegardingLead.Lead.Contact.Id.Value, conn, false));
                }
                else if (regopportunityid != null && regopportunityid.HasValue)
                {
                    viewModel.RegardingOpportunity = new ViewModels.Activities.ActivityRegardingOpportunityViewModel()
                    {
                        Type = new ViewModels.Activities.ActivityRegardingTypeViewModel()
                        {
                            Id = 2
                        }
                    };

                    viewModel.RegardingOpportunity.Opportunity         = Mapper.Map <ViewModels.Opportunities.OpportunityViewModel>(Data.Opportunities.Opportunity.Get(regopportunityid.Value, conn, false));
                    viewModel.RegardingOpportunity.Opportunity.Account = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(viewModel.RegardingOpportunity.Opportunity.Account.Id.Value, conn, false));
                }
                else
                {
                    throw new ArgumentException("Must have regleadid or regopportunityid.");
                }

                dynamic profile = System.Web.Profile.ProfileBase.Create(currentUser.Username);
                viewModel.Owner = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(int.Parse(profile.ContactId), conn, false));
                viewModel.Type  = Mapper.Map <ViewModels.Activities.ActivityTypeViewModel>(Data.Activities.ActivityType.Get("Phone Call", conn, false));
            }

            ViewBag.DirectionList    = directionList;
            ViewBag.StatusReasonList = statusReasonList;
            ViewBag.PriorityList     = priorityList;

            viewModel.Body               = string.Empty;
            viewModel.Due                = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 17, 0, 0, DateTimeKind.Local);
            viewModel.Duration           = 30;
            viewModel.IsCampaignResponse = false;
            viewModel.State              = true;
            viewModel.Subject            = string.Empty;

            return(View(viewModel));
        }
Beispiel #2
0
        public ActionResult Edit(long id)
        {
            Common.Models.Account.Users currentUser;
            ViewModels.Activities.ActivityPhonecallViewModel           viewModel        = new ViewModels.Activities.ActivityPhonecallViewModel();
            List <ViewModels.Activities.ActivityDirectionViewModel>    directionList    = new List <ViewModels.Activities.ActivityDirectionViewModel>();
            List <ViewModels.Activities.ActivityStatusReasonViewModel> statusReasonList = new List <ViewModels.Activities.ActivityStatusReasonViewModel>();
            List <ViewModels.Activities.ActivityPriorityViewModel>     priorityList     = new List <ViewModels.Activities.ActivityPriorityViewModel>();

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                currentUser = Data.Account.Users.Get(User.Identity.Name, conn, false);

                Common.Models.Activities.ActivityPhonecall model = Data.Activities.ActivityPhonecall.Get(id, conn, false);
                model.Direction    = Data.Activities.ActivityDirection.Get(model.Direction.Id.Value, conn, false);
                model.Owner        = Data.Contacts.Contact.Get(model.Owner.Id.Value, conn, false);
                model.Sender       = Data.Contacts.Contact.Get(model.Sender.Id.Value, conn, false);
                model.Recipient    = Data.Contacts.Contact.Get(model.Recipient.Id.Value, conn, false);
                model.Priority     = Data.Activities.ActivityPriority.Get(model.Priority.Id.Value, conn, false);
                model.StatusReason = Data.Activities.ActivityStatusReason.Get(model.StatusReason.Id.Value, conn, false);
                model.Type         = Data.Activities.ActivityType.Get(model.Type.Id.Value, conn, false);

                viewModel           = Mapper.Map <ViewModels.Activities.ActivityPhonecallViewModel>(model);
                viewModel.Owner     = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Owner);
                viewModel.Sender    = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Sender);
                viewModel.Recipient = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Recipient);

                Common.Models.Activities.ActivityRegardingType regtype = Data.Activities.ActivityRegardingType.GetFromActivityId(model.Id.Value, conn, false);

                if (regtype.Title == "Lead")
                {
                    Common.Models.Activities.ActivityRegardingLead ar = Data.Activities.ActivityRegardingLead.GetFromActivityId(model.Id.Value, conn, false);
                    ar.Lead                              = Data.Leads.Lead.Get(ar.Lead.Id.Value, conn, false);
                    ar.Lead.Contact                      = Data.Contacts.Contact.Get(ar.Lead.Contact.Id.Value, conn, false);
                    viewModel.RegardingLead              = Mapper.Map <ViewModels.Activities.ActivityRegardingLeadViewModel>(ar);
                    viewModel.RegardingLead.Lead         = Mapper.Map <ViewModels.Leads.LeadViewModel>(ar.Lead);
                    viewModel.RegardingLead.Lead.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(ar.Lead.Contact);
                    viewModel.RegardingLead.Type         = Mapper.Map <ViewModels.Activities.ActivityRegardingTypeViewModel>(regtype);
                }
                else
                {
                    Common.Models.Activities.ActivityRegardingOpportunity ao = Data.Activities.ActivityRegardingOpportunity.GetFromActivityId(model.Id.Value, conn, false);
                    ao.Opportunity                                     = Data.Opportunities.Opportunity.Get(ao.Opportunity.Id.Value, conn, false);
                    ao.Opportunity.Account                             = Data.Contacts.Contact.Get(ao.Opportunity.Account.Id.Value, conn, false);
                    viewModel.RegardingOpportunity                     = Mapper.Map <ViewModels.Activities.ActivityRegardingOpportunityViewModel>(ao);
                    viewModel.RegardingOpportunity.Opportunity         = Mapper.Map <ViewModels.Opportunities.OpportunityViewModel>(ao.Opportunity);
                    viewModel.RegardingOpportunity.Opportunity.Account = Mapper.Map <ViewModels.Contacts.ContactViewModel>(ao.Opportunity.Account);
                    viewModel.RegardingOpportunity.Type                = Mapper.Map <ViewModels.Activities.ActivityRegardingTypeViewModel>(regtype);
                }

                Data.Activities.ActivityDirection.List(conn, false).ForEach(x =>
                {
                    ViewModels.Activities.ActivityDirectionViewModel vm = Mapper.Map <ViewModels.Activities.ActivityDirectionViewModel>(x);
                    directionList.Add(vm);
                });

                Data.Activities.ActivityStatusReason.List(conn, false).ForEach(x =>
                {
                    ViewModels.Activities.ActivityStatusReasonViewModel vm = Mapper.Map <ViewModels.Activities.ActivityStatusReasonViewModel>(x);
                    statusReasonList.Add(vm);
                });

                Data.Activities.ActivityPriority.List(conn, false).ForEach(x =>
                {
                    ViewModels.Activities.ActivityPriorityViewModel vm = Mapper.Map <ViewModels.Activities.ActivityPriorityViewModel>(x);
                    priorityList.Add(vm);
                });
            }

            ViewBag.DirectionList    = directionList;
            ViewBag.StatusReasonList = statusReasonList;
            ViewBag.PriorityList     = priorityList;

            return(View(viewModel));
        }