Ejemplo n.º 1
0
        public async Task <ActionResult> SetScore(SetScoreViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", "Set Scores: Model state is invalid");
                    return(View(model));
                }
                if (model.Id == null)
                {
                    ModelState.AddModelError("", "Set Scores: No ID");
                    return(View(model));
                }
                GameGolfer gameGolfer = await _gameGolferRepo.FindByID(model.Id);

                gameGolfer.Score = model.Score;
                var isSuccess = await _gameGolferRepo.Update(gameGolfer);

                if (!isSuccess)
                {
                    ModelState.AddModelError("", "Set Scores: Unable to update the score");
                    return(View(model));
                }
                return(RedirectToAction(nameof(SetScore), new { id = model.GameId }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Set Scores: Something went wrong in setting the score");
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <ActionResult> SetGrad(int?id, SetScoreViewModel viewModel, FormCollection element)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    viewModel.Score = getGrid(element["scores"]);
                    _ElectionService.UpdateSetScore(viewModel);
                    await _unitOfWork.SaveChangesAsync();

                    CacheManager.InvalidateChildActionsCache();
                    return(RedirectToAction("Index", "Grading"));
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    string s = "";
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        s += String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                           eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            s += String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                               ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    ViewBag.err = s;
                    //throw;
                }
            }
            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public void UpdateSetScore(SetScoreViewModel viewModel)
        {
            var obj = GetById(viewModel.Id);

            obj.Score = viewModel.Score;
        }