Esempio n. 1
0
        public ActionResult List(Models.VoteSearchModel conditions, int count = 20)
        {
            try
            {
                var votes = RestfulVote.Search(conditions, 0, count, User.Identity.IsAuthenticated ? User.Identity.Name : null);

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

                return(Json
                       (
                           new
                {
                    Entities = RestfulJsonProccessor.Vote.List(votes, User.Identity.IsAuthenticated ? User.Identity.Name : null)
                },
                           JsonRequestBehavior.AllowGet
                       ));
            }
            catch
            {
                Response.StatusCode = 404;
                return(null);
            }
        }
Esempio n. 2
0
 public IEnumerable <Models.Vote> Search(Models.VoteSearchModel conditions = null, int start = 0, int count = 0, string userName = null)
 {
     try
     {
         return(RestfulVote.Search(conditions, start, count));
     }
     catch
     {
         throw;
     }
 }
Esempio n. 3
0
 public Models.Vote First(Models.VoteSearchModel conditions = null)
 {
     try
     {
         return(Search(conditions, 0, 1).First());
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 4
0
        public Models.Vote First(Models.VoteSearchModel conditions = null, string userName = null)
        {
            try
            {
                var entity = RestfulVote.First(conditions);

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

                return(entity);
            }
            catch
            {
                throw;
            }
        }
Esempio n. 5
0
        public IEnumerable <Models.Vote> Search(Models.VoteSearchModel conditions = null, int start = 0, int count = -1)
        {
            try
            {
                IEnumerable <Models.Vote> fs =
                    (
                        from vote in
                        DbEntities.Votes.OrderByDescending(m => m.Id)
                        where
                        (
                            ((conditions.IdLower == null || conditions.IdLower < 1) ? true : vote.Id < conditions.IdLower) &&
                            ((conditions.IdUpper == null || conditions.IdUpper < 1) ? true : vote.Id > conditions.IdUpper) &&
                            ((conditions.ReviewId == null || conditions.ReviewId < 1) ? true : vote.ReviewId == conditions.ReviewId) &&
                            ((conditions.Supportive == null) ? true : vote.Supportive == conditions.Supportive) &&
                            (string.IsNullOrEmpty(conditions.Creator) ? true : vote.Creator == conditions.Creator)
                        )
                        select vote
                    ).AsEnumerable();

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

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

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