public ActionResult Edit(long id)
        {
            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                Common.Models.Activities.ActivityType type = Data.Activities.ActivityType.GetByActivityId(id, conn, false);

                if (type.Title == "Phone Call")
                {
                    return(RedirectToAction("Edit", "ActivityPhonecalls", new { id = id }));
                }
                else if (type.Title == "Email")
                {
                    return(RedirectToAction("Edit", "ActivityEmails", new { id = id }));
                }
                else if (type.Title == "Letter")
                {
                    return(RedirectToAction("Edit", "ActivityLetters", new { id = id }));
                }
                else if (type.Title == "Task")
                {
                    return(RedirectToAction("Edit", "ActivityTasks", new { id = id }));
                }
                else
                {
                    throw new ArgumentException("Unknown type");
                }
            }
        }
Example #2
0
        public void BuildMappings()
        {
            Mapper.CreateMap <Common.Models.Activities.ActivityRegardingOpportunity, ActivityRegardingOpportunityViewModel>()
            .ForMember(dst => dst.IsStub, opt => opt.UseValue(false))
            .ForMember(dst => dst.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(dst => dst.Type, opt => opt.ResolveUsing(db =>
            {
                if (db.Type == null || !db.Type.Id.HasValue)
                {
                    return(null);
                }
                return(new ViewModels.Activities.ActivityRegardingTypeViewModel()
                {
                    Id = db.Type.Id.Value,
                    IsStub = true
                });
            }))
            .ForMember(dst => dst.Activity, opt => opt.ResolveUsing(db =>
            {
                if (db.Activity == null || !db.Activity.Id.HasValue)
                {
                    return(null);
                }

                Common.Models.Activities.ActivityType type = Data.Activities.ActivityType.GetByActivityId(db.Activity.Id.Value);

                if (type.Title == "Phone Call")
                {
                    return new ViewModels.Activities.ActivityPhonecallViewModel()
                    {
                        Id     = db.Activity.Id,
                        IsStub = true
                    }
                }
                ;
                else if (type.Title == "Email")
                {
                    return new ViewModels.Activities.ActivityEmailViewModel()
                    {
                        Id     = db.Activity.Id,
                        IsStub = true
                    }
                }
                ;
                else if (type.Title == "Letter")
                {
                    return new ViewModels.Activities.ActivityLetterViewModel()
                    {
                        Id     = db.Activity.Id,
                        IsStub = true
                    }
                }
                ;
                else if (type.Title == "Task")
                {
                    return new ViewModels.Activities.ActivityTaskViewModel()
                    {
                        Id     = db.Activity.Id,
                        IsStub = true
                    }
                }
                ;
                else
                {
                    throw new System.InvalidOperationException("db.Activity.Type of unknown value");
                }
            }))
            .ForMember(dst => dst.Opportunity, opt => opt.ResolveUsing(db =>
            {
                if (db.Opportunity == null || !db.Opportunity.Id.HasValue)
                {
                    return(null);
                }
                return(new ViewModels.Opportunities.OpportunityViewModel()
                {
                    Id = db.Opportunity.Id.Value,
                    IsStub = true
                });
            }));

            Mapper.CreateMap <ActivityRegardingOpportunityViewModel, Common.Models.Activities.ActivityRegardingOpportunity>()
            .ForMember(dst => dst.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(dst => dst.Type, opt => opt.ResolveUsing(x =>
            {
                if (x.Type == null || !x.Type.Id.HasValue)
                {
                    return(null);
                }
                return(new ViewModels.Activities.ActivityRegardingTypeViewModel()
                {
                    Id = x.Type.Id.Value
                });
            }))
            .ForMember(dst => dst.Activity, opt => opt.ResolveUsing(db =>
            {
                if (db.Activity == null || !db.Activity.Id.HasValue)
                {
                    return(null);
                }

                // ActivityTask has all properties of base and no more
                Common.Models.Activities.ActivityTask activity = Data.Activities.ActivityTask.Get(db.Activity.Id.Value);

                if (activity.Type.Title == "Phone Call")
                {
                    return new Common.Models.Activities.ActivityPhonecall()
                    {
                        Id     = activity.Id,
                        IsStub = true
                    }
                }
                ;
                else if (activity.Type.Title == "Email")
                {
                    return new Common.Models.Activities.ActivityEmail()
                    {
                        Id     = activity.Id,
                        IsStub = true
                    }
                }
                ;
                else if (activity.Type.Title == "Letter")
                {
                    return new Common.Models.Activities.ActivityLetter()
                    {
                        Id     = activity.Id,
                        IsStub = true
                    }
                }
                ;
                else if (activity.Type.Title == "Task")
                {
                    return new Common.Models.Activities.ActivityTask()
                    {
                        Id     = activity.Id,
                        IsStub = true
                    }
                }
                ;
                else
                {
                    throw new System.InvalidOperationException("db.Activity.Type of unknown value");
                }
            }))
            .ForMember(dst => dst.Opportunity, opt => opt.ResolveUsing(x =>
            {
                if (x.Opportunity == null || !x.Opportunity.Id.HasValue)
                {
                    return(null);
                }
                return(new ViewModels.Opportunities.OpportunityViewModel()
                {
                    Id = x.Opportunity.Id.Value
                });
            }));
        }
        public ActionResult Details(long id, bool preventRedirect = false)
        {
            ViewModels.Opportunities.OpportunityViewModel viewModel;
            Common.Models.Opportunities.Opportunity       model;

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                model = Data.Opportunities.Opportunity.Get(id, conn, false);

                if (model.Matter != null && model.Matter.Id.HasValue)
                {
                    if (!preventRedirect)
                    {
                        return(RedirectToAction("Details", "Matters", new { id = model.Matter.Id.Value }));
                    }
                    else
                    {
                        model.Matter = Data.Matters.Matter.Get(model.Matter.Id.Value, conn, false);
                    }
                }

                model.Lead = Data.Leads.Lead.Get(model.Lead.Id.Value, conn, false);
                if (model.Lead.Fee != null && model.Lead.Fee.Id.HasValue)
                {
                    model.Lead.Fee = Data.Leads.LeadFee.Get(model.Lead.Fee.Id.Value, conn, false);
                    if (model.Lead.Fee.To != null && model.Lead.Fee.To.Id.HasValue)
                    {
                        model.Lead.Fee.To = Data.Contacts.Contact.Get(model.Lead.Fee.To.Id.Value, conn, false);
                    }
                }
                model.Lead.Contact = Data.Contacts.Contact.Get(model.Lead.Contact.Id.Value, conn, false);
                model.Lead.Source  = Data.Leads.LeadSource.Get(model.Lead.Source.Id.Value, conn, false);
                if (model.Lead.Source.Type != null && model.Lead.Source.Type.Id.HasValue)
                {
                    model.Lead.Source.Type = Data.Leads.LeadSourceType.Get(model.Lead.Source.Type.Id.Value, conn, false);
                }
                model.Lead.Status = Data.Leads.LeadStatus.Get(model.Lead.Status.Id.Value, conn, false);
                model.Account     = Data.Contacts.Contact.Get(model.Account.Id.Value, conn, false);
                model.Stage       = Data.Opportunities.OpportunityStage.Get(model.Stage.Id.Value, conn, false);
                if (model.Matter != null && model.Matter.Id.HasValue)
                {
                    model.Matter = Data.Matters.Matter.Get(model.Matter.Id.Value, conn, false);
                }

                // Tweaks
                // Probability is stored as a decimal (<1) need to change representation to percent
                model.Probability *= 100;

                viewModel      = Mapper.Map <ViewModels.Opportunities.OpportunityViewModel>(model);
                viewModel.Lead = Mapper.Map <ViewModels.Leads.LeadViewModel>(model.Lead);
                if (model.Lead.Fee != null)
                {
                    viewModel.Lead.Fee = Mapper.Map <ViewModels.Leads.LeadFeeViewModel>(model.Lead.Fee);
                    if (model.Lead.Fee.To != null)
                    {
                        viewModel.Lead.Fee.To = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Lead.Fee.To);
                    }
                }
                viewModel.Lead.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Lead.Contact);
                viewModel.Lead.Source  = Mapper.Map <ViewModels.Leads.LeadSourceViewModel>(model.Lead.Source);
                if (model.Lead.Source.Type != null)
                {
                    viewModel.Lead.Source.Type = Mapper.Map <ViewModels.Leads.LeadSourceTypeViewModel>(model.Lead.Source.Type);
                }
                viewModel.Lead.Status = Mapper.Map <ViewModels.Leads.LeadStatusViewModel>(model.Lead.Status);
                viewModel.Account     = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Account);
                viewModel.Stage       = Mapper.Map <ViewModels.Opportunities.OpportunityStageViewModel>(model.Stage);
                if (model.Matter != null)
                {
                    viewModel.Matter = Mapper.Map <ViewModels.Matters.MatterViewModel>(model.Matter);
                }

                viewModel.Contacts = new List <ViewModels.Contacts.ContactViewModel>();
                Data.Opportunities.OpportunityContact.ListForOpportunity(id, conn, false).ForEach(x =>
                {
                    viewModel.Contacts.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(x.Contact.Id.Value)));
                });

                viewModel.Activities         = new List <ViewModels.Activities.ActivityBaseViewModel>();
                viewModel.InactiveActivities = new List <ViewModels.Activities.ActivityBaseViewModel>();
                Data.Opportunities.Opportunity.GetActivities(id, conn, false).ForEach(x =>
                {
                    Common.Models.Activities.ActivityStatusReason statusReason = Data.Activities.ActivityStatusReason.Get(x.StatusReason.Id.Value, conn, false);
                    Common.Models.Activities.ActivityType type     = Data.Activities.ActivityType.Get(x.Type.Id.Value);
                    ViewModels.Activities.ActivityBaseViewModel vm = Mapper.Map <ViewModels.Activities.ActivityBaseViewModel>(x);
                    vm.Type         = Mapper.Map <ViewModels.Activities.ActivityTypeViewModel>(type);
                    vm.StatusReason = Mapper.Map <ViewModels.Activities.ActivityStatusReasonViewModel>(statusReason);

                    if (x.State.HasValue && x.State.Value)
                    {
                        viewModel.Activities.Add(vm);
                    }
                    else
                    {
                        viewModel.InactiveActivities.Add(vm);
                    }
                });
            }

            return(View(viewModel));
        }
        public void BuildMappings()
        {
            Dapper.SqlMapper.SetTypeMap(typeof(ActivityRegardingLead), new ColumnAttributeTypeMapper <ActivityRegardingLead>());
            Mapper.CreateMap <ActivityRegardingLead, Common.Models.Activities.ActivityRegardingLead>()
            .ForMember(dst => dst.IsStub, opt => opt.UseValue(false))
            .ForMember(dst => dst.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(dst => dst.Type, opt => opt.ResolveUsing(db =>
            {
                if (!db.Type.HasValue)
                {
                    return(null);
                }
                return(new Common.Models.Activities.ActivityRegardingType()
                {
                    Id = db.Type.Value,
                    IsStub = true
                });
            }))
            .ForMember(dst => dst.Activity, opt => opt.ResolveUsing(db =>
            {
                if (!db.Activity.HasValue)
                {
                    return(null);
                }

                Common.Models.Activities.ActivityType type = Data.Activities.ActivityType.GetByActivityId(db.Activity.Value);

                if (type.Title == "Phone Call")
                {
                    return new Common.Models.Activities.ActivityPhonecall()
                    {
                        Id     = db.Activity,
                        IsStub = true
                    }
                }
                ;
                else if (type.Title == "Email")
                {
                    return new Common.Models.Activities.ActivityEmail()
                    {
                        Id     = db.Activity,
                        IsStub = true
                    }
                }
                ;
                else if (type.Title == "Letter")
                {
                    return new Common.Models.Activities.ActivityLetter()
                    {
                        Id     = db.Activity,
                        IsStub = true
                    }
                }
                ;
                else if (type.Title == "Task")
                {
                    return new Common.Models.Activities.ActivityTask()
                    {
                        Id     = db.Activity,
                        IsStub = true
                    }
                }
                ;
                else
                {
                    throw new System.InvalidOperationException("db.Activity.Type of unknown value");
                }
            }))
            .ForMember(dst => dst.Lead, opt => opt.ResolveUsing(db =>
            {
                if (!db.Lead.HasValue)
                {
                    return(null);
                }
                return(new Common.Models.Leads.Lead()
                {
                    Id = db.Lead.Value,
                    IsStub = true
                });
            }));

            Mapper.CreateMap <Common.Models.Activities.ActivityRegardingLead, ActivityRegardingLead>()
            .ForMember(dst => dst.Id, opt => opt.MapFrom(src => src.Id))
            .ForMember(dst => dst.Type, opt => opt.ResolveUsing(model =>
            {
                if (model.Type == null)
                {
                    return(null);
                }
                return(model.Type.Id);
            }))
            .ForMember(dst => dst.Activity, opt => opt.ResolveUsing(model =>
            {
                if (model.Activity == null)
                {
                    return(null);
                }
                return(model.Activity.Id);
            }))
            .ForMember(dst => dst.Lead, opt => opt.ResolveUsing(model =>
            {
                if (model.Lead == null)
                {
                    return(null);
                }
                return(model.Lead.Id);
            }));
        }
        public ActionResult Details(long id, bool preventRedirect = false)
        {
            ViewModels.Leads.LeadViewModel viewModel;
            Common.Models.Leads.Lead       model;

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                model = Data.Leads.Lead.Get(id, conn, false);

                // Has this already been made an opportunity?  If so, redirect
                Common.Models.Opportunities.Opportunity op = Data.Opportunities.Opportunity.GetForLead(model.Id.Value);
                if (op != null && !preventRedirect)
                {
                    return(new RedirectResult("/Opportunities/Details/" + op.Id.Value.ToString()));
                }

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

                if (op != null)
                {
                    viewModel.Opportunity = Mapper.Map <ViewModels.Opportunities.OpportunityViewModel>(op);
                }

                if (model.Status != null && model.Status.Id.HasValue)
                {
                    model.Status     = Data.Leads.LeadStatus.Get(model.Status.Id.Value, conn, false);
                    viewModel.Status = Mapper.Map <ViewModels.Leads.LeadStatusViewModel>(model.Status);
                }

                if (model.Contact != null && model.Contact.Id.HasValue)
                {
                    model.Contact     = Data.Contacts.Contact.Get(model.Contact.Id.Value, conn, false);
                    viewModel.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Contact);
                }

                if (model.Source != null && model.Source.Id.HasValue)
                {
                    model.Source     = Data.Leads.LeadSource.Get(model.Source.Id.Value, conn, false);
                    viewModel.Source = Mapper.Map <ViewModels.Leads.LeadSourceViewModel>(model.Source);

                    if (model.Source.Contact != null && model.Source.Contact.Id.HasValue)
                    {
                        model.Source.Contact     = Data.Contacts.Contact.Get(model.Source.Contact.Id.Value, conn, false);
                        viewModel.Source.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Source.Contact);
                    }
                    if (model.Source.Type != null && model.Source.Type.Id.HasValue)
                    {
                        model.Source.Type     = Data.Leads.LeadSourceType.Get(model.Source.Type.Id.Value, conn, false);
                        viewModel.Source.Type = Mapper.Map <ViewModels.Leads.LeadSourceTypeViewModel>(model.Source.Type);
                    }
                }

                if (model.Fee != null && model.Fee.Id.HasValue)
                {
                    model.Fee     = Data.Leads.LeadFee.Get(model.Fee.Id.Value, conn, false);
                    viewModel.Fee = Mapper.Map <ViewModels.Leads.LeadFeeViewModel>(model.Fee);

                    if (model.Fee.To != null && model.Fee.To.Id.HasValue)
                    {
                        model.Fee.To     = Data.Contacts.Contact.Get(model.Fee.To.Id.Value, conn, false);
                        viewModel.Fee.To = Mapper.Map <ViewModels.Contacts.ContactViewModel>(model.Fee.To);
                    }
                }

                viewModel.Activities         = new List <ViewModels.Activities.ActivityBaseViewModel>();
                viewModel.InactiveActivities = new List <ViewModels.Activities.ActivityBaseViewModel>();
                Data.Leads.Lead.GetActivities(id, conn, false).ForEach(x =>
                {
                    Common.Models.Activities.ActivityStatusReason statusReason = Data.Activities.ActivityStatusReason.Get(x.StatusReason.Id.Value, conn, false);
                    Common.Models.Activities.ActivityType type     = Data.Activities.ActivityType.Get(x.Type.Id.Value, conn, false);
                    ViewModels.Activities.ActivityBaseViewModel vm = Mapper.Map <ViewModels.Activities.ActivityBaseViewModel>(x);
                    vm.Type         = Mapper.Map <ViewModels.Activities.ActivityTypeViewModel>(type);
                    vm.StatusReason = Mapper.Map <ViewModels.Activities.ActivityStatusReasonViewModel>(statusReason);

                    if (x.State.HasValue && x.State.Value)
                    {
                        viewModel.Activities.Add(vm);
                    }
                    else
                    {
                        viewModel.InactiveActivities.Add(vm);
                    }
                });
            }

            return(View(viewModel));
        }