예제 #1
0
        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());
        }
예제 #2
0
        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 }));
            }
        }