예제 #1
0
        public ActionResult MiniList(Models.CategorySearchModel conditions, int count = 20)
        {
            try
            {
                var cats = RestfulCategory.Search(conditions, 0, count, User.Identity.IsAuthenticated ? User.Identity.Name : null);

                if (cats == null || cats.Count() < 1)
                {
                    throw new Exception("NO FOUND");
                }

                return(Json
                       (
                           new
                {
                    Entities = RestfulJsonProccessor.Category.MiniList(cats, User.Identity.IsAuthenticated ? User.Identity.Name : null)
                },
                           JsonRequestBehavior.AllowGet
                       ));
            }
            catch
            {
                Response.StatusCode = 404;
                return(null);
            }
        }
예제 #2
0
 public Models.Category First(Models.CategorySearchModel conditions = null)
 {
     try
     {
         return(Search(conditions, 0, 1).First());
     }
     catch
     {
         return(null);
     }
 }
예제 #3
0
 public IEnumerable <Models.Category> Search(Models.CategorySearchModel conditions = null, int start = 0, int count = 0, string userName = null)
 {
     try
     {
         return(RestfulCategory.Search(conditions, start, count));
     }
     catch
     {
         throw;
     }
 }
예제 #4
0
        public Models.Category First(Models.CategorySearchModel conditions = null, string userName = null)
        {
            try
            {
                var entity = RestfulCategory.First(conditions);

                if (!CategoryAccessControl.Pass(RestfulAction.Read, entity, userName))
                {
                    throw new NoAccessException("No Access");
                }

                return(entity);
            }
            catch
            {
                throw;
            }
        }
예제 #5
0
        public IEnumerable <Models.Category> Search(Models.CategorySearchModel conditions = null, int start = 0, int count = -1)
        {
            try
            {
                IEnumerable <Models.Category> fs =
                    (
                        from Category in
                        DbEntities.Categories.OrderByDescending(m => m.Id)
                        where
                        (
                            ((conditions.IdLower == null || conditions.IdLower < 1) ? true : Category.Id < conditions.IdLower) &&
                            ((conditions.IdUpper == null || conditions.IdUpper < 1) ? true : Category.Id > conditions.IdUpper) &&
                            (string.IsNullOrEmpty(conditions.Title) ? true : Category.Title.Contains(conditions.Title)) &&
                            (string.IsNullOrEmpty(conditions.Abbreviation) ? true : Category.Abbreviation.Contains(conditions.Abbreviation)) &&
                            (string.IsNullOrEmpty(conditions.ChineseTitle) ? true : Category.ChineseTitle.Contains(conditions.ChineseTitle)) &&
                            (string.IsNullOrEmpty(conditions.Creator) ? true : Category.Creator == conditions.Creator)
                        )
                        select Category
                    ).AsEnumerable();

                if (start > 0)
                {
                    fs = fs.Skip(start);
                }

                if (count > 0)
                {
                    fs = fs.Take(count);
                }

                return(fs);
            }
            catch
            {
                return(null);
            }
        }