コード例 #1
0
        //
        // GET: /Budget/
        public ViewResult Index(string errorMessage, bool showAll = false)
        {
            var clientsWithBudget = new ClientsWithBudgetsViewModel(userManager.GetRoles(User.Identity.GetUserId()));
            var providerUserKey   = User.Identity.GetUserId();


            if (showAll)
            {
                foreach (var client in clientRepository.Where(c => c.IsActive).Include(c => c.Budgets).Include(c => c.Labels).Include(c => c.Consultant))
                {
                    clientsWithBudget.Clients.Add(new ClientWithLatestBudgetsViewModel(client));
                }
            }
            else
            {
                foreach (var client in clientRepository.Where(c => c.IsActive && ((c.Consultant != null && c.Consultant.Id == providerUserKey) || (c.AccountManager != null && c.AccountManager.Id == providerUserKey))).Include(c => c.Budgets).Include(c => c.Labels).Include(c => c.Consultant))
                {
                    clientsWithBudget.Clients.Add(new ClientWithLatestBudgetsViewModel(client));
                }
            }

            clientsWithBudget.Clients             = clientsWithBudget.Clients.OrderByDescending(c => c.HasUnHandledBudgets).ThenBy(c => c.ClientName).ToList();
            clientsWithBudget.HasUnhandledBudgets = clientsWithBudget.Clients.Any(c => c.HasUnHandledBudgets);
            clientsWithBudget.Error = errorMessage;
            return(View(clientsWithBudget));
        }
コード例 #2
0
        public ActionResult Index()
        {
            var chats        = new ChatListViewModel(userManager.GetRoles(User.Identity.GetUserId()));
            var chatEntities =
                chatRepository.Where(l => l.LeadType == "Chat")
                .Include(c => c.Interaction)
                .Include(c => c.Property)
                .AsNoTracking()
                .OrderByDescending(c => c.Date);

            foreach (var chatItemInRepository in chatEntities)
            {
                var chatViewModel = new ChatViewModel();
                chatViewModel.Id       = chatItemInRepository.Id;
                chatViewModel.ClientId = chatItemInRepository.ClientId;

                chatViewModel.Date = serverTime.ConvertServerTimeToStandardUserTime(chatItemInRepository.Date);
                if (chatItemInRepository.HasProperty("Description"))
                {
                    var description = chatItemInRepository.GetProperty("Description").Value;
                    if (description.Length > 60)
                    {
                        chatViewModel.Description = description.Substring(0, 57) + "...";
                    }
                    else
                    {
                        chatViewModel.Description = description;
                    }
                }
                if (chatItemInRepository.HasProperty("Email"))
                {
                    chatViewModel.Email = chatItemInRepository.GetProperty("Email").Value;
                }
                if (chatItemInRepository.HasProperty("Phone"))
                {
                    chatViewModel.Phone = chatItemInRepository.GetProperty("Phone").Value;
                }

                chatViewModel.ClientName = clientRepository.Where(cr => cr.Id == chatItemInRepository.ClientId).First().Name;
                chats.Collection.Add(chatViewModel);
            }
            return(View(chats));
        }
コード例 #3
0
        public ActionResult Index()
        {
            var accountManagers = new AccountManagerListViewModel(userManager.GetRoles(User.Identity.GetUserId()));

            foreach (var admin in userManager.GetUsers().Where(u => u.Role.Any(r => r.Name == "sales")))
            {
                var accountManagerViewModel = new AccountManagerViewModel
                {
                    Id          = admin.Id,
                    Email       = admin.Email,
                    ImageUrl    = admin.ImageUrl,
                    Name        = admin.Name,
                    Phone       = admin.Phone,
                    IsLockedOut = admin.IsLockedOut
                };

                accountManagers.Collection.Add(accountManagerViewModel);
            }
            return(View(accountManagers));
        }
コード例 #4
0
        public ViewResult Index(bool?showAllData, bool?showInactive)
        {
            var clientViewModels = new ClientsViewModel(userManager.GetRoles(User.Identity.GetUserId()));
            var providerUserKey  = User.Identity.GetUserId();

            if (showAllData == null)
            {
                showAllData = false;
            }
            IEnumerable <Client> clients = null;

            if (showInactive.HasValue && showInactive.Value)
            {
                clients = clientRepository.Where(c => !c.IsActive).Include(c => c.InsideUserSets);
            }
            else if (showAllData.HasValue && showAllData.Value)
            {
                clients = clientRepository.Where(c => c.IsActive).Include(c => c.InsideUserSets);
            }
            else
            {
                var adminId = _adminRepository.First(a => a.Id == providerUserKey).Id;

                clients = clientRepository
                          .Where(c => c.AccountManagerId == adminId || c.ConsultantId == adminId).Where(c => c.IsActive)
                          .Include(c => c.InsideUserSets)
                          .ToList();
            }

            foreach (var client in clients.ToList())
            {
                var clientViewModel = new ClientViewModel(client);

                DateTime?lastLogin = null;
                try
                {
                    var insideUserSets = client.InsideUserSets;
                    if (insideUserSets.Count > 0)
                    {
                        lastLogin = insideUserSets.Select(u => u.LastLoginDate).Max();
                    }
                }
                catch (Exception e)
                {
                    lastLogin = null;
                }


                clientViewModel.LastLogin = lastLogin;
                var now = DateTime.Now;
                if (!lastLogin.HasValue)
                {
                    clientViewModel.ActivityLevel = 0;
                }
                else if ((now - lastLogin.Value).Days < 7)
                {
                    clientViewModel.ActivityLevel = 2;
                }
                else if ((now - lastLogin.Value).Days < 30)
                {
                    clientViewModel.ActivityLevel = 1;
                }
                else
                {
                    clientViewModel.ActivityLevel = 0;
                }

                clientViewModels.Clients.Add(clientViewModel);
            }

            clientViewModels.Labels = labelRepository.All().ToList().Select(l => new LabelViewModel(l)).ToList();

            return(View(clientViewModels));
        }
コード例 #5
0
        public ActionResult Report(int clientId, DateTime startDate, DateTime endDate)
        {
            var client = clientRepository.First(c => c.Id == clientId);
            var clientViewModel = new ClientViewModel(client);
            var model = new CcoReportViewModel(userManager.GetRoles(User.Identity.GetUserId()), clientViewModel);

            model.Today = serverTime.RequestStarted;
            model.OnMonth = model.Today.AddMonths(-1);
            model.OneQuarter = model.Today.AddMonths(-3);
            model.OneYear = model.Today.AddMonths(-12);
            model.StartDate = startDate;
            model.EndDate = endDate;

            var tableId = client.AnalyticsTableId;

            var query = new AnalyticQuery
            {
                TabelId = tableId,
                StartDate = startDate,
                EndDate = endDate,
            };

            query.Metrics.AddMany("ga:adClicks", "ga:adCost");
            query.Dimenssions.AddMany("ga:keyword");
            query.MaxResults = 500;
            query.Filters.AddMany("ga:campaign!~Retargeting", "ga:campaign!~Remarketing", "ga:campaign!~Display");
            query.Sort = "-ga:adCost";
            var keywordRows = gaService.Get<KeyWordReport>(query);

            var keywordFinder = new Dictionary<string, KeyWordReport>();
            keywordRows.ForEach(k =>
            {
                model.KeyWords.Add(k);
                keywordFinder.Add(k.Keyword, k);
            });

            var searchPhrasesLeads = SearchPhrasesLeads(clientId, startDate, endDate);
            foreach (var searchPhraseLead in searchPhrasesLeads)
            {
                if (!string.IsNullOrEmpty(searchPhraseLead) && keywordFinder.ContainsKey(searchPhraseLead))
                {
                    keywordFinder[searchPhraseLead].NumLead = keywordFinder[searchPhraseLead].NumLead + 1;
                }
            }

            var searchPhrasesNotLeads = SearchPhrasesNotLeads(clientId, startDate, endDate);
            foreach (var searchPhraseNotLead in searchPhrasesNotLeads)
            {
                if (!string.IsNullOrEmpty(searchPhraseNotLead) && keywordFinder.ContainsKey(searchPhraseNotLead))
                {
                    keywordFinder[searchPhraseNotLead].NumNotALead = keywordFinder[searchPhraseNotLead].NumNotALead + 1;
                }
            }

            var searchPhrasesContacts = SearchPhrasesContacts(clientId, startDate, endDate);
            foreach (var searchPhraseContact in searchPhrasesContacts)
            {
                if (!string.IsNullOrEmpty(searchPhraseContact) && keywordFinder.ContainsKey(searchPhraseContact))
                {
                    keywordFinder[searchPhraseContact].Contacts = keywordFinder[searchPhraseContact].Contacts + 1;
                }
            }

            return View(model);
        }