Esempio n. 1
0
 public static List<AppCategoryListModel> GetGroupedApp(this IList<int> source, IAppService appService)
 {
     var list = new List<AppCategoryListModel>();
     foreach (var i in source)
     {
         var model = new AppCategoryListModel();
         var d = appService.List().Where(m => m.IsPublic==true && m.AppCategoryId == i).ToList().Select(m =>
         {
             var t = m.ToModel();
             t.AppCategoryName = m.AppCategory.Name;
             return t;
         });    
         model.AppCategoryName = d.First().AppCategoryName;
         model.AppModelList = d.ToList();
         list.Add(model);
     }
     return list;
 }
Esempio n. 2
0
        //获取用户喜好app,并按分组进行展示
        public ActionResult GetFancyAppAndAppCategory()
        {
            int roleId = GetUserRole();
            var userid = GetCookie().FirstOrDefault();
            if (roleId == 0) throw new NullReferenceException("Cookie is null");
            var data = this._userFancyAppService.GetUserFancyAppByUserId(int.Parse(userid)).Select(m => m.AppId);
            var apps = (from t in this._appService.List()
                        where data.Any(m => m == t.Id)
                        select t);
            var appCategorys = apps.Select(m => m.AppCategoryId).Distinct();
            var list = new List<AppCategoryListModel>();
            foreach (var i in appCategorys.ToList())
            {
                var appCategoryListModel = new AppCategoryListModel();
                var d = (from t in apps
                         where t.AppCategoryId == i
                         select t).ToList().Select(m =>
                         {
                             var s = m.ToModel();
                             s.AppCategoryName = m.AppCategory.Name;
                             return s;
                         });
                appCategoryListModel.AppCategoryName = d.First().AppCategoryName;
                appCategoryListModel.AppModelList = d.ToList();
                list.Add(appCategoryListModel);

            }
            return Content(JsonConvert.SerializeObject(list));
        }