Beispiel #1
0
        public ActionResult MonthlyPopularityData(int?Branch_Id = null)
        {
            IEnumerable <PopularityModel> model = dao.GetBranchMonthlyPopularity();

            if (Branch_Id != null)
            {
                model = model.Where(x => x.Branch_id == Branch_Id);
            }

            //this makes a dictionary where month int is the key and the val is the list of objects which share that month val.
            var monthDict = model.GroupBy(x => x.Month, x => x, (key, g) => new { Month = key, vals = g.ToList() }).OrderBy(x => x.Month);

            List <PopularityViewModel> result = new List <PopularityViewModel>();

            //converting the month data into the viewmodel for the chart
            foreach (var group in monthDict)
            {
                PopularityViewModel tmp = new PopularityViewModel();
                tmp.name = months[group.Month - 1];
                tmp.x    = group.vals.Select(x => x.Branch_Province).ToArray();
                tmp.y    = group.vals.Select(x => x.Avg_Rating).ToArray();

                result.Add(tmp);
            }

            return(Json(result.ToArray <PopularityViewModel>(), JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult OverallPopularityData(int?Branch_Id = null)
        {
            IEnumerable <PopularityModel> model = dao.GetBranchPopularity().OrderBy(x => x.Branch_Province);

            if (Branch_Id != null)
            {
                model = model.Where(x => x.Branch_id == Branch_Id);
            }

            PopularityViewModel result = new PopularityViewModel();

            result.x = model.Select(x => x.Branch_Province).ToArray <string>();
            result.y = model.Select(x => x.Avg_Rating).ToArray <float>();

            //result needs to be in an array for the JS library
            return(Json(new PopularityViewModel[] { result }, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult ItemPopularity(int?Branch_Id = null)
        {
            IEnumerable <PopularityModel> model = dao.GetBranchItemPopularity();

            if (Branch_Id != null)
            {
                model = model.Where(x => x.Branch_id == Branch_Id);
            }

            PopularityViewModel result = new PopularityViewModel();

            result.x = model.Select(x => x.Menu_Desc).ToArray <string>();
            result.y = model.Select(x => (float)x.Item_Count).ToArray <float>();

            //result needs to be in an array for the JS library
            return(Json(new PopularityViewModel[] { result }, JsonRequestBehavior.AllowGet));
        }