public CampaignListViewModel GetPaginatedCampaignsDinamic(List <FilterValue> filterValues, int pageSize, int pageNumber, Guid idAccount, IDataProtector protector, Guid userid, Guid _typeuser)
        {
#if DEBUG
            var myWatch = new Stopwatch();
            myWatch.Start();
#endif

            var itemResult     = new CampaignListViewModel();
            var campaigns      = _campaignDao.GetPaginatedCampaignListbyUser(filterValues, pageSize, pageNumber, idAccount, userid, _typeuser);
            var countCampaigns = _campaignDao.GetPaginatedCampaignCount(filterValues, pageSize, pageNumber, idAccount, _typeuser, userid);
            var _data          = _taskCampaignDao.statusAllow(idAccount, pageNumber, pageSize);
            foreach (var campaign in campaigns)
            {
                var ts = campaign.EndDate - DateTime.Now;

                int numberNotImplementedTasks;
                int numberStartedTasks;
                int numberPendingTasks;
                int numberImplementedTasks;
                //var totalTasks = GetCampaignStatistics(idAccount, campaign, out numberNotImplementedTasks, out numberStartedTasks, out numberPendingTasks, out numberImplementedTasks);
                var totalTasks   = _campaignDao.NumbertaskbyCampaign(campaign.Id);
                var usercampaign = _userCanpaignDao.GetCampaignById(campaign.Id, userid);
                if (_typeuser.Equals(new Guid("30DB815C-8B82-47EE-9279-B28922BEB616")))
                {
                    if (usercampaign.Count > 0)
                    {
                        var cvm = new CampaignItemViewModel
                        {
                            EndDate       = campaign.EndDate,
                            Id            = protector.Protect(campaign.Id.ToString()),
                            Name          = campaign.Name,
                            StartDate     = campaign.StartDate,
                            RemainingDays = ts.Days,

                            //ImplementedTaskPercent = (totalTasks > 0) ? ((numberImplementedTasks * 100) / totalTasks) + "%" : "0%",
                            //NotImplementedTaskPercent = (totalTasks > 0) ? ((numberNotImplementedTasks * 100) / totalTasks) + "%" : "0%",
                            //StartedTaskPercent = (totalTasks > 0) ? ((numberStartedTasks * 100) / totalTasks) + "%" : "0%",
                            //PendingTaskPercent = (totalTasks > 0) ? ((numberPendingTasks * 100) / totalTasks) + "%" : "0%",
                            //CountImplementedTasks = numberImplementedTasks,
                            //CountNotImplementedTasks = numberNotImplementedTasks,
                            //CountPendingTasks = numberPendingTasks,
                            //CountStartedTasks = numberStartedTasks,
                            TotalTasks = totalTasks
                        };
                        int aux = 0;
                        int max = 0;

                        foreach (var allow in _data)
                        {
                            aux = _taskCampaignDao.GetTaskCountByCampaignAndStatusStadi(allow.Name, campaign.Id, idAccount);
                            max = (aux > max) ? aux : max;
                            cvm.sectionCampaign.Add(new SectionCampaignDinamicViewModels  {
                                name = allow.Name, total = aux, percent = (totalTasks > 0) ? ((aux * 100) / totalTasks) + "%" : "0%", color = allow
                                                                                                                                              .color
                            });
                        }
                        itemResult.CampaignList.Add(cvm);
                    }
                }
                else
                {
                    var cvm = new CampaignItemViewModel
                    {
                        EndDate       = campaign.EndDate,
                        Id            = protector.Protect(campaign.Id.ToString()),
                        Name          = campaign.Name,
                        StartDate     = campaign.StartDate,
                        RemainingDays = ts.Days,

                        //ImplementedTaskPercent = (totalTasks > 0) ? ((numberImplementedTasks * 100) / totalTasks) + "%" : "0%",
                        //NotImplementedTaskPercent = (totalTasks > 0) ? ((numberNotImplementedTasks * 100) / totalTasks) + "%" : "0%",
                        //StartedTaskPercent = (totalTasks > 0) ? ((numberStartedTasks * 100) / totalTasks) + "%" : "0%",
                        //PendingTaskPercent = (totalTasks > 0) ? ((numberPendingTasks * 100) / totalTasks) + "%" : "0%",
                        //CountImplementedTasks = numberImplementedTasks,
                        //CountNotImplementedTasks = numberNotImplementedTasks,
                        //CountPendingTasks = numberPendingTasks,
                        //CountStartedTasks = numberStartedTasks,

                        TotalTasks = totalTasks
                    };
                    int aux = 0;
                    int max = 0;

                    foreach (var allow in _data)
                    {
                        aux = _taskCampaignDao.GetTaskCountByCampaignAndStatusStadi(allow.Name, campaign.Id, idAccount);
                        max = (aux > max) ? aux : max;
                        cvm.sectionCampaign.Add(new SectionCampaignDinamicViewModels
                        {
                            name    = allow.Name,
                            total   = aux,
                            percent = (totalTasks > 0) ? ((aux * 100) / totalTasks) + "%" : "0%",
                            color   = allow
                                      .color
                        });
                    }

                    itemResult.CampaignList.Add(cvm);
                }
            }

#if DEBUG
            myWatch.Stop();
            Debugger.Log(0, "Campañas", $"ms: {myWatch.ElapsedMilliseconds}");
#endif

            return(ConfigurePagination(itemResult, pageNumber, pageSize, filterValues, countCampaigns));
        }
Exemplo n.º 2
0
        public CampaignListViewModel GetPaginatedCampaigns(List <FilterValue> filterValues, int pageSize, int pageNumber, Guid idAccount, IDataProtector protector, Guid userid, Guid _typeuser)
        {
#if DEBUG
            var myWatch = new Stopwatch();
            myWatch.Start();
#endif

            var itemResult     = new CampaignListViewModel();
            var campaigns      = _campaignDao.GetPaginatedCampaignList(filterValues, pageSize, pageNumber, idAccount);
            var countCampaigns = _campaignDao.GetPaginatedCampaignCount(filterValues, pageSize, pageNumber, idAccount);

            foreach (var campaign in campaigns)
            {
                var ts = campaign.EndDate - DateTime.Now;

                int numberNotImplementedTasks;
                int numberStartedTasks;
                int numberPendingTasks;
                int numberImplementedTasks;
                var totalTasks = GetCampaignStatistics(idAccount, campaign, out numberNotImplementedTasks, out numberStartedTasks, out numberPendingTasks, out numberImplementedTasks);

                var usercampaign = _userCanpaignDao.GetCampaignById(campaign.Id, userid);
                if (_typeuser.Equals(new Guid("30DB815C-8B82-47EE-9279-B28922BEB616")))
                {
                    if (usercampaign.Count > 0)
                    {
                        var cvm = new CampaignItemViewModel
                        {
                            EndDate       = campaign.EndDate,
                            Id            = protector.Protect(campaign.Id.ToString()),
                            Name          = campaign.Name,
                            StartDate     = campaign.StartDate,
                            RemainingDays = ts.Days,

                            ImplementedTaskPercent    = (totalTasks > 0) ? ((numberImplementedTasks * 100) / totalTasks) + "%" : "0%",
                            NotImplementedTaskPercent = (totalTasks > 0) ? ((numberNotImplementedTasks * 100) / totalTasks) + "%" : "0%",
                            StartedTaskPercent        = (totalTasks > 0) ? ((numberStartedTasks * 100) / totalTasks) + "%" : "0%",
                            PendingTaskPercent        = (totalTasks > 0) ? ((numberPendingTasks * 100) / totalTasks) + "%" : "0%",
                            CountImplementedTasks     = numberImplementedTasks,
                            CountNotImplementedTasks  = numberNotImplementedTasks,
                            CountPendingTasks         = numberPendingTasks,
                            CountStartedTasks         = numberStartedTasks,
                            TotalTasks = totalTasks
                        };


                        itemResult.CampaignList.Add(cvm);
                    }
                }
                else
                {
                    var cvm = new CampaignItemViewModel
                    {
                        EndDate       = campaign.EndDate,
                        Id            = protector.Protect(campaign.Id.ToString()),
                        Name          = campaign.Name,
                        StartDate     = campaign.StartDate,
                        RemainingDays = ts.Days,

                        ImplementedTaskPercent    = (totalTasks > 0) ? ((numberImplementedTasks * 100) / totalTasks) + "%" : "0%",
                        NotImplementedTaskPercent = (totalTasks > 0) ? ((numberNotImplementedTasks * 100) / totalTasks) + "%" : "0%",
                        StartedTaskPercent        = (totalTasks > 0) ? ((numberStartedTasks * 100) / totalTasks) + "%" : "0%",
                        PendingTaskPercent        = (totalTasks > 0) ? ((numberPendingTasks * 100) / totalTasks) + "%" : "0%",
                        CountImplementedTasks     = numberImplementedTasks,
                        CountNotImplementedTasks  = numberNotImplementedTasks,
                        CountPendingTasks         = numberPendingTasks,
                        CountStartedTasks         = numberStartedTasks,
                        TotalTasks = totalTasks
                    };


                    itemResult.CampaignList.Add(cvm);
                }
            }

#if DEBUG
            myWatch.Stop();
            Debugger.Log(0, "Campañas", $"ms: {myWatch.ElapsedMilliseconds}");
#endif

            return(ConfigurePagination(itemResult, pageNumber, pageSize, filterValues, countCampaigns));
        }
 public List <UserCanpaign> GetUserCampaignById(Guid idCampaign, Guid idUser)
 {
     return(_userCanpaignDao.GetCampaignById(idCampaign, idUser));
 }