コード例 #1
0
        public async Task <ActionResult> RemoveLinkFlair(int id)
        {
            // get link flair for selected subverse
            var linkFlairToRemove = await _db.SubverseFlair.FindAsync(id);

            if (linkFlairToRemove == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.NotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var subverse = DataCache.Subverse.Retrieve(linkFlairToRemove.Subverse);

            if (subverse == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            // check if caller has clearance to remove a link flair
            if (!ModeratorPermission.HasPermission(User, subverse.Name, Domain.Models.ModeratorAction.ModifyFlair))
            {
                return(RedirectToAction("Index", "Home"));
            }

            // execute removal
            var subverseFlairSetting = await _db.SubverseFlair.FindAsync(id);

            _db.SubverseFlair.Remove(subverseFlairSetting);
            await _db.SaveChangesAsync();

            //clear cache
            CacheHandler.Instance.Remove(CachingKey.SubverseFlair(subverse.Name));

            return(RedirectToAction("SubverseFlairSettings"));
        }
コード例 #2
0
        public ActionResult AddLinkFlair(SubverseFlairInput subverseFlairSetting)
        {
            if (!ModelState.IsValid)
            {
                return(View("~/Views/Subverses/Admin/Flair/AddLinkFlair.cshtml", subverseFlairSetting));
            }

            //check perms
            if (!ModeratorPermission.HasPermission(User, subverseFlairSetting.Subverse, Domain.Models.ModeratorAction.ModifyFlair))
            {
                return(RedirectToAction("Index", "Home"));
            }

            // get model for selected subverse
            var subverse = DataCache.Subverse.Retrieve(subverseFlairSetting.Subverse);

            if (subverse == null)
            {
                return(HybridError(ErrorViewModel.GetErrorViewModel(ErrorType.SubverseNotFound)));
            }
            var count = _db.SubverseFlair.Count(x => x.Subverse == subverseFlairSetting.Subverse);

            if (count >= 20)
            {
                ViewBag.SubverseModel    = subverse;
                ViewBag.SubverseName     = subverse.Name;
                ViewBag.SelectedSubverse = string.Empty;
                SetNavigationViewModel(subverse.Name);
                ModelState.AddModelError("", "Subverses are limited to 20 flairs");
                return(View("~/Views/Subverses/Admin/Flair/AddLinkFlair.cshtml", subverseFlairSetting));
            }

            subverseFlairSetting.Subverse = subverse.Name;
            _db.SubverseFlair.Add(new SubverseFlair()
            {
                Label    = subverseFlairSetting.Label,
                CssClass = subverseFlairSetting.CssClass,
                Subverse = subverseFlairSetting.Subverse
            });
            _db.SaveChanges();

            //clear cache
            CacheHandler.Instance.Remove(CachingKey.SubverseFlair(subverse.Name));

            return(RedirectToAction("SubverseFlairSettings"));
        }