public IActionResult OnPost() { Rungtynes dateCheck = _repository.GetMatchByDate(date); if (ModelState.IsValid) { if (dateCheck != null) { ModelState.AddModelError("UserDataInvalid", "Tokios rungtynės jau yra sukurtos"); return(Page()); } Rungtynes match = new Rungtynes() { HomeTeamID = HomeTeam, AwayTeamID = AwayTeam, StartDate = date }; if (HomeTeam == AwayTeam) { ModelState.AddModelError("UserDataInvalid", "Tos pačios komandos žaisti negali"); return(Page()); } else { _repository.AddNewMatch(match); _repository.SaveChanges(); return(RedirectToPage("/Index")); } } return(Page()); }
public void UpdateRungtynes(Rungtynes rungtynes) { Rungtynes rungtynesFromDb = _context.Rungtynes.FirstOrDefault(item => item.ID == rungtynes.ID); rungtynesFromDb.HomeTeamScore = rungtynes.HomeTeamScore; rungtynesFromDb.AwayTeamScore = rungtynes.AwayTeamScore; rungtynesFromDb.HomeTeamID = rungtynes.HomeTeamID; rungtynesFromDb.AwayTeamID = rungtynes.AwayTeamID; rungtynesFromDb.StartDate = rungtynes.StartDate; }
public IActionResult OnGet() { Rungtynes = _repository.GetRungtynesByRungtynesID(RungtyniuID); if (User.Claims.FirstOrDefault(item => item.Type == ClaimTypes.Role).Value != "1") { return(RedirectToPagePermanent("Index")); } return(Page()); }
public IActionResult OnPost() { List <Zaidejas> zaidejuListas = new List <Zaidejas>(); for (int i = 0; i < Points.Count; i++) { Zaidejas zaidejas = _repository.GetZaidejasIdByName(Vardas[i]); RungtyniuStatistika rungtyniuStatistika = new RungtyniuStatistika() { ZaidejasID = zaidejas.ID, MIN = Minutes[i], PTS = Points[i], REB = Rebounds[i], AST = Assists[i], TOV = Turnovers[i], BLK = Blocks[i], PF = PersonalFouls[i], RungtynesID = RungtyniuID, GautuTaskuKiekis = (Points[i] * 2) + (Rebounds[i] * 3) + (Assists[i] * 3) - (Turnovers[i] * 2) - (PersonalFouls[i] * 3) }; if (Convert.ToInt32(rungtyniuStatistika.MIN.Split(":")[0]) != 0 || Convert.ToInt32(rungtyniuStatistika.MIN.Split(":")[1]) != 0) { zaidejas.TotalPoints += Points[i]; zaidejas.TotalRebounds += Rebounds[i]; zaidejas.TotalAssist += Assists[i]; zaidejas.TotalTurnovers += Turnovers[i]; zaidejas.TotalBlocks += Blocks[i]; zaidejas.TotalPersonalFouls += PersonalFouls[i]; zaidejas.GamesPlayer += 1; zaidejas.Kaina = (((double)(zaidejas.TotalPoints / zaidejas.GamesPlayer) + (double)(zaidejas.TotalAssist / zaidejas.GamesPlayer) + (double)(zaidejas.TotalRebounds / zaidejas.GamesPlayer) + (double)(zaidejas.TotalBlocks / zaidejas.GamesPlayer) - (double)(zaidejas.TotalPersonalFouls / zaidejas.GamesPlayer) - (double)(zaidejas.TotalTurnovers / zaidejas.GamesPlayer)) * 100); } _repository.UpdateZaidejas(zaidejas); _repository.AddPlayerStatistic(rungtyniuStatistika); } Rungtynes newRungtynes = _repository.GetRungtynesByRungtynesID(RungtyniuID); newRungtynes.HomeTeamScore = HomeScore; newRungtynes.AwayTeamScore = AwayScore; _repository.UpdateRungtynes(newRungtynes); _repository.SaveChanges(); return(RedirectToPagePermanent("Index")); }
public async Task <JsonResult> OnGetCreateOrEditAsync(int id = 0) { if (id == 0) { Rungtynes rungtynes = new Rungtynes(); rungtynes.komanduList = new SelectList(_repository.GetAllKomandos().ToList(), nameof(Komanda.ID), nameof(Komanda.Pavadinimas)); return(new JsonResult(new { isValid = true, html = await _renderService.ToStringAsync("PartialView/_APMatchCreateOrEdit", rungtynes) })); } else { var match = _repository.GetAllMatches().FirstOrDefault(item => item.ID == id); match.komanduList = new SelectList(_repository.GetAllKomandos(), nameof(Komanda.ID), nameof(Komanda.Pavadinimas)); return(new JsonResult(new { isValid = true, html = await _renderService.ToStringAsync("PartialView/_APMatchCreateOrEdit", match) })); } }
public async Task <JsonResult> OnPostCreateOrEditAsync(int id, Rungtynes rungtynes) { if (ModelState.IsValid) { if (id == 0) { if (rungtynes.HomeTeamID == rungtynes.AwayTeamID) { } else { _repository.AddNewMatch(rungtynes); _repository.SaveChanges(); } } else { if (rungtynes.HomeTeamID == rungtynes.AwayTeamID) { } else { _repository.UpdateRungtynes(rungtynes); _repository.SaveChanges(); } } Rungtynes = _repository.GetAllMatches(); var html = await _renderService.ToStringAsync("PartialView/_APMatchView", Rungtynes); return(new JsonResult(new { isValid = true, html })); } else { var html = await _renderService.ToStringAsync("PartialView/_APMatchCreateOrEdit", rungtynes); return(new JsonResult(new { isValid = false, html })); } }
public void AddNewMatch(Rungtynes rungtynes) { _context.Rungtynes.Add(rungtynes); }
public void DeleteMatch(Rungtynes rungtynes) { _context.Remove(rungtynes); }