예제 #1
0
        public ActionResult StatisticsTime(int?month)
        {
            if (!month.HasValue)
            {
                Syslog.Write("Unknown statistic request");
                return(Content(""));
            }
            var analytics = new GoogleAnalytics();

            analytics.GetVisitorStatistics(accountHostname, DateTime.UtcNow.AddMonths(month.Value), DateTime.UtcNow);
            var viewdata = new VisitorStatistics(analytics.stats, DateTime.UtcNow.AddMonths(month.Value), DateTime.UtcNow);

            return(View(viewdata));
        }
예제 #2
0
        public ActionResult Index()
        {
            // user is logged in
            var user = repository.GetUserById(sessionid.Value, subdomainid.Value);

            // check if account has been setup properly
            if (role.HasFlag(UserRole.CREATOR) && !MASTERdomain.currency.HasValue)
            {
                return(RedirectToAction("setup", "register", new { Area = "" }));
            }

            var activityGroups = new ActivityGroup
            {
                tradelr = new TradelrActivity()
                {
                    filterList =
                        typeof(ActivityType).ToSelectList().ToFilterList()
                }
            };

            if (role.HasFlag(UserRole.CREATOR))
            {
                // for admin
                // tradelr activity
                activityGroups.tradelr.activities = repository.GetActivities(subdomainid.Value)
                                                    .OrderByDescending(x => x.id)
                                                    .ToAdminList(sessionid.Value)
                                                    .Take(GeneralConstants.ACTIVITY_ROWS_PER_PAGE)
                                                    .ToModel();
            }
            else
            {
                // for user
                activityGroups.tradelr.activities =
                    repository.GetActivities(subdomainid.Value)
                    .OrderByDescending(x => x.id)
                    .ToUserList(sessionid.Value)
                    .Take(GeneralConstants.ACTIVITY_ROWS_PER_PAGE)
                    .ToModel();
            }


            // handle statistics
            if (role == UserRole.USER)
            {
                // show account stats
                Statistics statistics = null;
                if (baseviewmodel.permission.HasFlag(UserPermission.NETWORK_STORE | UserPermission.TRANSACTION_VIEW | UserPermission.INVENTORY_VIEW))
                {
                    var analytics = new GoogleAnalytics();
                    analytics.GetVisitorStatistics(accountHostname, DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow);
                    statistics = new Statistics(analytics.stats, DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow);
                    statistics.InitSalesAndProductsStatistics(repository, subdomainid.Value, sessionid.Value,
                                                              user.organisation1.MASTERsubdomain);
                }

                // this is for scenario where user is not registered but someone has send them
                // an invoice or purchase order
                var home = new HomeViewData(baseviewmodel)
                {
                    activities = activityGroups,
                    isAdmin    = false,
                    stats      = statistics
                };

                return(View(home));
            }
            else // for admins, god and staff
            {
                // which activity panel?
                var paneltype = repository.GetActivityPanel(sessionid.Value);

                var analytics = new GoogleAnalytics();
                analytics.GetVisitorStatistics(accountHostname, DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow);
                var statistics = new Statistics(analytics.stats, DateTime.UtcNow.AddMonths(-1), DateTime.UtcNow);
                statistics.InitSalesAndProductsStatistics(repository, subdomainid.Value, sessionid.Value,
                                                          user.organisation1.MASTERsubdomain);

                var home = new HomeViewData(baseviewmodel)
                {
                    stats      = statistics, // from baseController
                    activities = activityGroups,
                    panelIndex = paneltype.ToIndex(),
                    isAdmin    = true
                };

                return(View(home));
            }
        }