예제 #1
0
        public ActionResult ModeratorDeleteRecord(int id)
        {
            if (!IsModerator)
            {
                _logger.Error($"Non-moderator attempted to delete record: [{id}]");
                return(Content("unauthorized access"));
            }

            _logger.Info($"Moderator deleting record: [{id}]");

            var record = _leaderboardService.GetRecord(id);

            if (record == null)
            {
                return(new HttpNotFoundResult());
            }

            // Get category to ensure it's enabled
            var category = CategoryService.GetCategory(record.CategoryId);

            if (category == null)
            {
                return(new HttpUnauthorizedResult());
            }

            if (!_leaderboardService.DeleteRecord(UserContext, record))
            {
                _logger.Error($"Failed to delete record: [{id}], [{record.Player}], [{category.UrlName}]");
                return(Content("error deleting record"));
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult DeleteRecord(int id)
        {
            _logger.Info($"Moderator deleting record: [{id}]");

            var record = _leaderboardService.GetRecord(id);

            if (record == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, "Record not found");
            }

            // Get category to ensure it's enabled
            var category = CategoryService.GetCategory(record.CategoryId);

            if (category == null)
            {
                throw new ApiException(HttpStatusCode.BadRequest, "Can't delete records in a disabled category");
            }

            if (!_leaderboardService.DeleteRecord(UserContext, record))
            {
                _logger.Error($"Failed to delete record: [{id}], [{record.Player}], [{category.UrlName}]");
                throw new ApiException("Failed to delete record");
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }