public ActionResult SubmitTime(string categoryUrlName, string gameTime, string escapeGameTime, string realTime, string videoLink, string comment, string username)
        {
            var category = CategoryService.GetCategoryByUrlName(categoryUrlName);

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

            if ((category.GameTime && string.IsNullOrWhiteSpace(gameTime)) ||
                (category.EscapeGameTime && string.IsNullOrWhiteSpace(escapeGameTime)) ||
                (category.RealTime && string.IsNullOrWhiteSpace(realTime)))
            {
                return(GetSubmitTimeView(category, "Please fill out the time fields"));
            }

            var isModeratorAction = false;

            if (IsModerator && !string.IsNullOrWhiteSpace(username))
            {
                // Allow moderators to submit for any username
                username          = username.Trim();
                isModeratorAction = true;

                _logger.Info($"Moderator submitting record for another user: [{username}]");
            }
            else
            {
                username = Username;
            }

            var record = CreateRecord(category, username, gameTime, escapeGameTime, realTime, videoLink, comment);

            if (record == null)
            {
                return(GetSubmitTimeView(category, "Invalid time"));
            }

            _leaderboardService.AddRecord(UserContext, record, isModeratorAction);

            _logger.Debug($"Record submitted: [{categoryUrlName}], [{gameTime}], [{escapeGameTime}], [{realTime}], [{videoLink}], [{comment}]");

            var viewModel = CreateViewModel <PageViewModel>();

            return(View("SubmitSuccess", viewModel));
        }
Beispiel #2
0
        public ActionResult SubmitRecord(string username, string category, string realTime, string gameTime, string escapeGameTime, string videoUrl, string comment)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ApiException(HttpStatusCode.BadRequest, "Username required");
            }

            if (string.IsNullOrWhiteSpace(category))
            {
                throw new ApiException(HttpStatusCode.BadRequest, "Category required");
            }

            var categoryObj = CategoryService.GetCategoryByUrlName(category);

            if (categoryObj == null)
            {
                throw new ApiException(HttpStatusCode.BadRequest, "Invalid category");
            }

            if ((categoryObj.GameTime && string.IsNullOrWhiteSpace(gameTime)) ||
                (categoryObj.EscapeGameTime && string.IsNullOrWhiteSpace(escapeGameTime)) ||
                (categoryObj.RealTime && string.IsNullOrWhiteSpace(realTime)))
            {
                throw new ApiException(HttpStatusCode.BadRequest, "Time required");
            }

            var record = RecordUtil.CreateRecord(categoryObj, username, gameTime, escapeGameTime, realTime, videoUrl, comment, UserId);

            if (record == null)
            {
                throw new ApiException(HttpStatusCode.BadRequest, "Invalid time");
            }

            _leaderboardService.AddRecord(UserContext, record, true);

            _logger.Debug($"Record submitted: [{category}], [{gameTime}], [{escapeGameTime}], [{realTime}], [{videoUrl}], [{comment}]");

            var mappedRecord = MapRecord(record);

            return(Json(mappedRecord));
        }