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)); } }
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)); }
public void UpdateSetScore(SetScoreViewModel viewModel) { var obj = GetById(viewModel.Id); obj.Score = viewModel.Score; }