コード例 #1
0
        public async Task <IActionResult> EditPosition(BetGroupBindingModel model, int id, string returnUrl = "/")
        {
            if (!ModelState.IsValid)
            {
                this.ModelState.AddModelError(string.Empty, "Validation error.");
                return(View(moderationService.PrepareGroupScore(id)));
            }

            var distTeams = model.Teams.Select(x => x.Position).Distinct().ToArray();

            if (distTeams.Length != model.Teams.Count)
            {
                this.ModelState.AddModelError(string.Empty, "No dublicate positions are allowed.");
                return(View(moderationService.PrepareGroupScore(id)));
            }

            try
            {
                var result = await moderationService.EditGroupScoreAsync(id, model);

                if (result != null)
                {
                    this.ModelState.AddModelError(string.Empty, result);
                    return(View(new BetGroupBindingModel()));
                }

                return(Redirect(returnUrl));
            }
            catch
            {
                return(Redirect("/"));
            }
        }