public IActionResult AddScore(int testOrExamId, string traineeId) { var model = new ScoresVM { TestOrExamId = testOrExamId, TraineeId = traineeId }; return(View(model)); }
public ActionResult Contact() { ScoresVM model = new ScoresVM { Choices = ScoresGenerate() }; return(View(model)); }
public IActionResult AddScore(ScoresVM model) { if (ModelState.IsValid) { var testOrExam = _testsAndExamsRepository.FindById(model.TestOrExamId); if (model.Score > testOrExam.Total) { ModelState.AddModelError("", "The value of the trainee's score cannot be higher than the total score"); return(View(model)); } var score = _mapper.Map <Scores>(model); var isSuccess = _scoresRepository.Create(score); if (!isSuccess) { return(View("Error", "Home")); } return(RedirectToAction("ListTraineesForTest", new { testOrExamId = score.TestOrExamId })); } ModelState.AddModelError("", "FIll all the fields properly"); return(View(model)); }
public ActionResult SaveScore(ScoresVM model) { // Sprawdzenia model state if (!ModelState.IsValid) { return(View(model)); } // zmniejszenie wyników meczu o jeden --model.Score1; --model.Score2; // Pobranie id użytkownika model.UserId = User.Identity.GetUserId(); // Generowanie daty oddania głosu model.Betdate = DateTime.Now; using (Db db = new Db()) { // Inicjalizacja PageDTO ScoresDTO dto = new ScoresDTO(); /////////////////// #region TO USE VALIDATION //// gdy niemamy adresu strony to przypisujemy tytul //if (string.IsNullOrWhiteSpace(model.Slug)) //{ // slug = model.Title.Replace(" ", "-").ToLower(); //} //else //{ // slug = model.Slug.Replace(" ", "-").ToLower(); //} //// zapobiegamy dodanie takiej samej nazwy strony //if (db.Pages.Any(x => x.Title == model.Title) || db.Pages.Any(x => x.Slug == slug)) //{ // ModelState.AddModelError("", "Ten tytuł lub adres strony już istnieje."); // return View(model); //} #endregion /////////////////// dto.Score1 = model.Score1; dto.Score2 = model.Score2; dto.GameId = model.GameId; dto.BetDate = model.Betdate; dto.UserId = model.UserId; // zapis DTO db.Scores.Add(dto); db.SaveChanges(); } //utworzenie zmiennej sesyjnej Session["score"] = model.Score1.ToString() + " - " + model.Score2.ToString(); return(RedirectToAction("LoadScore")); }
public Scores() { VMGame = new ScoresVM(); this.InitializeComponent(); }