public static Common.Models.Activities.ActivityRegardingLead Create(
     Transaction t,
     Common.Models.Activities.ActivityRegardingLead model,
     Common.Models.Account.Users creator)
 {
     return(Create(model, creator, t.Connection, false));
 }
 public static Common.Models.Activities.ActivityRegardingLead Edit(
     Transaction t,
     Common.Models.Activities.ActivityRegardingLead model,
     Common.Models.Account.Users modifier)
 {
     return(Edit(model, modifier, t.Connection, false));
 }
Exemple #3
0
        public ActionResult Details(long id)
        {
            ViewModels.Activities.ActivityPhonecallViewModel viewModel = new ViewModels.Activities.ActivityPhonecallViewModel();

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                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.Direction    = Mapper.Map <ViewModels.Activities.ActivityDirectionViewModel>(model.Direction);
                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);
                viewModel.Priority     = Mapper.Map <ViewModels.Activities.ActivityPriorityViewModel>(model.Priority);
                viewModel.StatusReason = Mapper.Map <ViewModels.Activities.ActivityStatusReasonViewModel>(model.StatusReason);
                viewModel.Type         = Mapper.Map <ViewModels.Activities.ActivityTypeViewModel>(model.Type);

                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);
                }

                PopulateCoreDetails(viewModel, conn);
            }

            return(View(viewModel));
        }
        public static Common.Models.Activities.ActivityRegardingLead Edit(
            Common.Models.Activities.ActivityRegardingLead model,
            Common.Models.Account.Users modifier,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            DBOs.Activities.ActivityRegardingLead dbo = Mapper.Map <DBOs.Activities.ActivityRegardingLead>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            conn.Execute("UPDATE \"activity_regarding_lead\" SET " +
                         "\"type\"=@Type, \"activity\"=@Activity, \"lead\"=@Lead " +
                         "WHERE \"id\"=@Id", dbo);

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
        public static Common.Models.Activities.ActivityRegardingLead Create(
            Common.Models.Activities.ActivityRegardingLead model,
            Common.Models.Account.Users creator,
            IDbConnection conn   = null,
            bool closeConnection = true)
        {
            DBOs.Activities.ActivityRegardingLead dbo = Mapper.Map <DBOs.Activities.ActivityRegardingLead>(model);

            conn = DataHelper.OpenIfNeeded(conn);

            if (conn.Execute("INSERT INTO \"activity_regarding_lead\" (\"type\", \"activity\", \"lead\") " +
                             "VALUES (@Type, @Activity, @Lead)",
                             dbo) > 0)
            {
                model.Id = conn.Query <DBOs.Activities.ActivityRegardingLead>("SELECT currval(pg_get_serial_sequence('activity_regarding_lead', 'id')) AS \"id\"").Single().Id;
            }

            DataHelper.Close(conn, closeConnection);

            return(model);
        }
Exemple #6
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));
        }
Exemple #7
0
        public ActionResult Create(ViewModels.Activities.ActivityPhonecallViewModel viewModel)
        {
            Common.Models.Account.Users currentUser;
            Common.Models.Activities.ActivityPhonecall model;

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

                    model      = Mapper.Map <Common.Models.Activities.ActivityPhonecall>(viewModel);
                    model.Type = Data.Activities.ActivityType.Get(trans, "Phone Call");

                    if (!model.IsCampaignResponse.HasValue)
                    {
                        model.IsCampaignResponse = false;
                    }

                    model = Data.Activities.ActivityPhonecall.Create(trans, model, currentUser);

                    if (viewModel.RegardingLead != null && viewModel.RegardingLead.Lead != null && viewModel.RegardingLead.Lead.Id.HasValue)
                    {
                        Common.Models.Activities.ActivityRegardingLead arl = new Common.Models.Activities.ActivityRegardingLead()
                        {
                            Lead = new Common.Models.Leads.Lead()
                            {
                                Id = viewModel.RegardingLead.Lead.Id
                            },
                            Activity = model,
                            Type     = new Common.Models.Activities.ActivityRegardingType()
                            {
                                Id = 1
                            }
                        };
                        Data.Activities.ActivityRegardingLead.Create(trans, arl, currentUser);

                        trans.Commit();

                        return(RedirectToAction("Details", "Leads", new { Id = viewModel.RegardingLead.Lead.Id }));
                    }
                    else if (viewModel.RegardingOpportunity != null && viewModel.RegardingOpportunity.Opportunity != null && viewModel.RegardingOpportunity.Opportunity.Id.HasValue)
                    {
                        Common.Models.Activities.ActivityRegardingOpportunity aro = new Common.Models.Activities.ActivityRegardingOpportunity()
                        {
                            Opportunity = new Common.Models.Opportunities.Opportunity()
                            {
                                Id = viewModel.RegardingOpportunity.Opportunity.Id
                            },
                            Activity = model,
                            Type     = new Common.Models.Activities.ActivityRegardingType()
                            {
                                Id = 2
                            }
                        };
                        Data.Activities.ActivityRegardingOpportunity.Create(trans, aro, currentUser);

                        trans.Commit();

                        return(RedirectToAction("Details", "Opportunities", new { Id = viewModel.RegardingOpportunity.Opportunity.Id }));
                    }
                    else
                    {
                        throw new ArgumentException("Unkown regarding entity.");
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(RedirectToAction("Create"));
                }
            }
        }
        public ActionResult Index(ViewModels.Home.DashboardViewModel currentDVM)
        {
            int id;

            ViewModels.Home.DashboardViewModel      viewModel;
            Common.Models.Contacts.Contact          employee;
            Common.Models.Account.Users             currentUser;
            List <Common.Models.Settings.TagFilter> tagFilter;

            Common.Models.Matters.Matter matter;
            List <ViewModels.Contacts.ContactViewModel> employeeContactList;

            employeeContactList = new List <ViewModels.Contacts.ContactViewModel>();

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                try
                {
                    Data.Account.Users.List(conn, false);
                }
                catch (Exception)
                {
                    return(RedirectToAction("Index", "Installation"));
                }

                if (RouteData.Values["Id"] != null)
                {
                    id = int.Parse((string)RouteData.Values["Id"]);
                }
                else if (currentDVM.Employee != null && currentDVM.Employee.Id.HasValue)
                {
                    id = currentDVM.Employee.Id.Value;
                }
                else
                {
                    dynamic profile = ProfileBase.Create(Membership.GetUser().UserName);
                    if (profile.ContactId != null && !string.IsNullOrEmpty(profile.ContactId))
                    {
                        id = int.Parse(profile.ContactId);
                    }
                    else
                    {
                        id = -1; // Happens on initial setup
                    }
                }

                if (id <= 0)
                {
                    employee  = null;
                    viewModel = null;
                }
                else
                {
                    employee    = Data.Contacts.Contact.Get(id, conn, false);
                    currentUser = Data.Account.Users.Get(User.Identity.Name, conn, false);

                    viewModel          = new ViewModels.Home.DashboardViewModel();
                    viewModel.Employee = Mapper.Map <ViewModels.Contacts.ContactViewModel>(employee);

                    viewModel.MyTodoList = new List <Tuple <ViewModels.Matters.MatterViewModel, ViewModels.Tasks.TaskViewModel> >();

                    Data.Tasks.Task.GetTodoListFor(employee, null, null, conn, false).ForEach(x =>
                    {
                        matter = Data.Tasks.Task.GetRelatedMatter(x.Id.Value, conn, false);
                        viewModel.MyTodoList.Add(
                            new Tuple <ViewModels.Matters.MatterViewModel, ViewModels.Tasks.TaskViewModel>(
                                Mapper.Map <ViewModels.Matters.MatterViewModel>(matter),
                                Mapper.Map <ViewModels.Tasks.TaskViewModel>(x)));
                    });

                    viewModel.NotificationList = new List <ViewModels.Notes.NoteNotificationViewModel>();
                    Data.Notes.NoteNotification.ListAllNoteNotificationsForContact(employee.Id.Value, conn, false).ForEach(x =>
                    {
                        ViewModels.Notes.NoteNotificationViewModel nnvm = Mapper.Map <ViewModels.Notes.NoteNotificationViewModel>(x);
                        nnvm.Note = Mapper.Map <ViewModels.Notes.NoteViewModel>(Data.Notes.Note.Get(x.Note.Id.Value, conn, false));
                        viewModel.NotificationList.Add(nnvm);
                    });

                    Data.Contacts.Contact.ListEmployeesOnly(conn, false).ForEach(x =>
                    {
                        employeeContactList.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(x));
                    });

                    viewModel.TasklessActiveMatters = new List <ViewModels.Matters.MatterViewModel>();
                    Data.Matters.Matter.ListMattersWithoutActiveTasks(5, conn, false).ForEach(x =>
                    {
                        viewModel.TasklessActiveMatters.Add(Mapper.Map <ViewModels.Matters.MatterViewModel>(x));
                    });

                    viewModel.Activities = new List <Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel> >();
                    Data.Activities.ActivityTask.GetGeneralActivities(employee.Id.Value, conn, false).ForEach(x =>
                    {
                        Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel> vm = null;
                        ViewModels.Activities.ActivityBaseViewModel vm1;

                        x.Type = Data.Activities.ActivityType.Get(x.Type.Id.Value, conn, false);

                        vm1      = Mapper.Map <ViewModels.Activities.ActivityBaseViewModel>(x);
                        vm1.Type = Mapper.Map <ViewModels.Activities.ActivityTypeViewModel>(x.Type);

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

                        if (regardingModel.Title == "Lead")
                        {
                            Common.Models.Activities.ActivityRegardingLead lm = Data.Activities.ActivityRegardingLead.GetFromActivityId(x.Id.Value, conn, false);
                            vm = new Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel>(vm1,
                                                                                                                                               Mapper.Map <ViewModels.Activities.ActivityRegardingLeadViewModel>(lm));
                        }
                        else if (regardingModel.Title == "Opportunity")
                        {
                            Common.Models.Activities.ActivityRegardingOpportunity om = Data.Activities.ActivityRegardingOpportunity.GetFromActivityId(x.Id.Value, conn, false);
                            vm = new Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel>(vm1,
                                                                                                                                               Mapper.Map <ViewModels.Activities.ActivityRegardingOpportunityViewModel>(om));
                        }

                        viewModel.Activities.Add(vm);
                    });

                    Random rnd                       = new Random();
                    int    activeMatters             = Data.Matters.Matter.CountAllActiveMatters(conn, false);
                    int    activeMattersWithoutTasks = Data.Matters.Matter.CountAllMattersWithoutActiveTasks(conn, false);
                    ViewBag.MattersWithActiveTasks    = activeMatters - activeMattersWithoutTasks;
                    ViewBag.MattersWithoutActiveTasks = activeMattersWithoutTasks;
                }
            }

            ViewBag.EmployeeContactList = employeeContactList;

            return(View(viewModel));
        }