Ejemplo n.º 1
0
        public ActionResult List(Models.CommentSearchModel conditions, int count = 20)
        {
            try
            {
                var comments = RestfulComment.Search(conditions, 0, count, User.Identity.IsAuthenticated ? User.Identity.Name : null);

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

                return(Json
                       (
                           new
                {
                    Entities = RestfulJsonProccessor.Comment.List(comments, User.Identity.IsAuthenticated ? User.Identity.Name : null)
                },
                           JsonRequestBehavior.AllowGet
                       ));
            }
            catch
            {
                Response.StatusCode = 404;
                return(null);
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <Models.Comment> Search(Models.CommentSearchModel conditions = null, int start = 0, int count = -1)
        {
            try
            {
                IEnumerable <Models.Comment> fs =
                    (
                        from comment in
                        DbEntities.Comments.OrderByDescending(m => m.Id)
                        where
                        (
                            ((conditions.IdLower == null || conditions.IdLower < 1) ? true : comment.Id < conditions.IdLower) &&
                            ((conditions.IdUpper == null || conditions.IdUpper < 1) ? true : comment.Id > conditions.IdUpper) &&
                            ((conditions.ReviewId == null || conditions.ReviewId < 1) ? true : comment.ReviewId == conditions.ReviewId) &&
                            (string.IsNullOrEmpty(conditions.Creator) ? true : comment.Creator == conditions.Creator)
                        )
                        select comment
                    ).AsEnumerable();

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

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

                return(fs);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
 public Models.Comment First(Models.CommentSearchModel conditions = null)
 {
     try
     {
         return(Search(conditions, 0, 1).First());
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 4
0
 public IEnumerable <Models.Comment> Search(Models.CommentSearchModel conditions = null, int start = 0, int count = 0, string userName = null)
 {
     try
     {
         return(RestfulComment.Search(conditions, start, count));
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 5
0
        public Models.Comment First(Models.CommentSearchModel conditions = null, string userName = null)
        {
            try
            {
                var entity = RestfulComment.First(conditions);

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

                return(entity);
            }
            catch
            {
                throw;
            }
        }