示例#1
0
        public ActionResult _ajax_GetSparklineStat(int course, int company, int department, string start, string end)
        {
            bool superadmin = SessionManager.inst.IsSuperadmin();
            bool admin      = SessionManager.inst.IsAdmin();
            bool manager    = SessionManager.inst.IsManager();

            if (!superadmin)
            {
                company = company != 0 ? company : SessionManager.inst.Company().Id;
            }
            if (manager && !admin)
            {
                department = department != 0 ? department : SessionManager.inst.User().DepartmentId;
            }
            var      customCourseId = StatisticsRepository.MasterId2customId(course, company, department, 0).FirstOrDefault();
            DateTime?startDateTime  = null;
            DateTime?endDateTime    = null;
            var      result         = new Dictionary <string, int>();

            if (!start.Equals(""))
            {
                startDateTime = DateTime.ParseExact(start, dateFormat, CultureInfo.InvariantCulture);
            }
            if (!end.Equals(""))
            {
                endDateTime = DateTime.ParseExact(end, dateFormat, CultureInfo.InvariantCulture);
            }
            var started = 0;
            var ended   = 0;

            if (customCourseId != 0)
            {
                var customCourseIds = StatisticsRepository.masterId2customIds(course);
                for (var i = 0; i < customCourseIds.Count(); i++)
                {
                    started += StatisticsRepository.CourseWeekStatistics(customCourseIds[i], company, department, startDateTime, endDateTime, 0);
                    ended   += StatisticsRepository.CoursesWeekStatistics(customCourseIds[i], company, department, startDateTime, endDateTime, 0);
                }
            }
            else
            {
                started += StatisticsRepository.CourseWeekStatistics(customCourseId, company, department, startDateTime, endDateTime, 0);
                ended   += StatisticsRepository.CoursesWeekStatistics(customCourseId, company, department, startDateTime, endDateTime, 0);
            }
            result.Add("started", started);
            result.Add("ended", ended);
            var json = new JavaScriptSerializer().Serialize(result);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }