Ejemplo n.º 1
0
        public ActionResult EditSet(int setId)
        {
            var setToEdit = _db.Usersets.FirstOrDefault(s => s.Set_id == setId);

            if (setToEdit != null)
            {
                // check if user owns the set and abort
                if (!Utils.User.IsUserSetOwner(User.Identity.Name, setToEdit.Set_id)) return RedirectToAction("UnAuthorized", "Error");

                // get list of subverses for the set
                var setSubversesList = _db.Usersetdefinitions.Where(s => s.Set_id == setToEdit.Set_id).ToList();

                // populate viewmodel for the set
                var setViewModel = new SingleSetViewModel()
                {
                    Name = setToEdit.Name,
                    Description = setToEdit.Description,
                    SubversesList = setSubversesList,
                    Id = setToEdit.Set_id,
                    Created = setToEdit.Created_on,
                    Subscribers = setToEdit.Subscribers
                };

                return View("~/Views/Sets/EditSet.cshtml", setViewModel);
            }
            return RedirectToAction("NotFound", "Error");
        }
Ejemplo n.º 2
0
        // GET: /set/setid
        // show single set frontpage
        public ActionResult SingleSet(int setId, int? page)
        {
            const int pageSize = 25;
            int recordsToSkip = (page ?? 0);
            try
            {
                // get list of subverses for the set
                // for each subverse, get top ranked submissions
                var set = _db.Usersets.FirstOrDefault(ds => ds.Set_id == setId);

                if (set == null) return RedirectToAction("NotFound", "Error");

                ViewBag.SelectedSubverse = set.Name;
                var singleSetResultModel = new SingleSetViewModel();
                var submissions = new List<SetSubmission>();

                // if subs in set count is < 1, don't display the page, instead, check if the user owns this set and give them a chance to add subs to the set
                if (set.Usersetdefinitions.Count < 1)
                {
                    // check if the user owns this sub
                    if (User.Identity.IsAuthenticated && User.Identity.Name == set.Created_by)
                    {
                        return RedirectToAction("EditSet", "Sets", new { setId = set.Set_id });
                    }
                }

                int subsInSet = set.Usersetdefinitions.Count();
                int submissionsToGet = 5;

                // there is at least 1 sub in the set
                if (subsInSet == 1)
                {
                    submissionsToGet = 25;
                }
                // get only one submission from each sub if set contains 25 or more subverses
                else if (subsInSet >= 25)
                {
                    submissionsToGet = 1;
                }
                // try to aim for 25 submissions
                else
                {
                    submissionsToGet = (int)Math.Ceiling((double)25 / subsInSet);
                }

                foreach (var subverse in set.Usersetdefinitions)
                {
                    // get top ranked submissions for current subverse
                    Subverse currentSubverse = subverse.Subverse;

                    if (currentSubverse != null)
                    {
                        // skip parameter could be passed here
                        submissions.AddRange(SetsUtility.TopRankedSubmissionsFromASub(currentSubverse.name, _db.Messages, set.Name, submissionsToGet, recordsToSkip * pageSize));
                    }
                    singleSetResultModel.Name = set.Name;
                    singleSetResultModel.Description = set.Description;
                    singleSetResultModel.Id = set.Set_id;
                }

                singleSetResultModel.SubmissionsList = new List<SetSubmission>(submissions.OrderByDescending(s => s.Rank));

                return View("~/Views/Sets/Index.cshtml", singleSetResultModel);
            }
            catch (Exception)
            {
                return RedirectToAction("HeavyLoad", "Error");
            }
        }
Ejemplo n.º 3
0
        // GET: /set/setId/page
        // fetch x more items from a set
        public ActionResult SingleSetPage(int setId, int page)
        {
            const int pageSize = 2;
            try
            {
                // get list of subverses for the set
                // for each subverse, get top ranked submissions
                var set = _db.Usersets.FirstOrDefault(ds => ds.Set_id == setId);

                if (set == null) return new HttpStatusCodeResult(HttpStatusCode.NotFound);

                ViewBag.SelectedSubverse = set.Name;
                var singleSetResultModel = new SingleSetViewModel();
                var submissions = new List<SetSubmission>();

                foreach (var subverse in set.Usersetdefinitions)
                {
                    // get 5 top ranked submissions for current subverse
                    Subverse currentSubverse = subverse.Subverse;

                    if (currentSubverse != null)
                    {
                        // skip parameter could be passed here
                        submissions.AddRange(SetsUtility.TopRankedSubmissionsFromASub(currentSubverse.name, _db.Messages, set.Name, pageSize, page * pageSize));
                    }
                    singleSetResultModel.Name = set.Name;
                    singleSetResultModel.Description = set.Description;
                    singleSetResultModel.Id = set.Set_id;
                }

                singleSetResultModel.SubmissionsList = new List<SetSubmission>(submissions.OrderByDescending(s => s.Rank).ThenByDescending(s => s.Date));

                if (submissions.Any())
                {
                    ViewBag.Page = page;
                    return PartialView("~/Views/Sets/_SingleSetPage.cshtml", singleSetResultModel);
                }

                // no more entries found
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            catch (Exception)
            {
                return RedirectToAction("HeavyLoad", "Error");
            }
        }