public async Task <IActionResult> Add(AddRoundViewModel addRoundViewModel)
        {
            if (ModelState.IsValid)
            {
                //adding a new round to my existing rounds (***up to 20 rounds***)
                //add in calculation for score differential here then ill be able to add to database in the below add and save

                float ScoreDifferential = (addRoundViewModel.Score - addRoundViewModel.Rating)
                                          * 113 / addRoundViewModel.Slope;

                //Round to two decimal places for ending score differential
                ScoreDifferential.ToString("n2");

                Round newRound = new Round
                {
                    Course            = addRoundViewModel.Course,
                    Score             = addRoundViewModel.Score,
                    Slope             = addRoundViewModel.Slope,
                    Rating            = addRoundViewModel.Rating,
                    ScoreDifferential = ScoreDifferential,
                    UserID            = UserManager.GetUserId(User)
                };

                var isAuthorized = await AuthorizationService.AuthorizeAsync(
                    User, newRound,
                    RoundOperations.Create);

                if (!isAuthorized.Succeeded)
                {
                    return(Forbid());
                }

                Context.Rounds.Add(newRound);
                await Context.SaveChangesAsync();

                return(Redirect("/Round"));
            }

            return(View(addRoundViewModel));
        }
        /*[HttpGet]
         * public ActionResult Round()
         * {
         *
         *  return View();
         * }
         * [HttpPost]
         * public ActionResult Round(Round round)
         * {
         *  round.ScoreDifferential = (round.Score - round.Rating) * 113 / round.Slope;
         *  ViewData["Round"] = round.ScoreDifferential;
         *  return View(round);
         * }*/

        public IActionResult Add()
        {
            AddRoundViewModel addRoundViewModel = new AddRoundViewModel();

            return(View(addRoundViewModel));
        }
Пример #3
0
        public async Task <IActionResult> Post([FromBody] AddRoundViewModel model)
        {
            var round = await _roundService.Create(model.RoundName, model.TournamentId);

            return(Json(round.Id));
        }