public async Task <IActionResult> Create([Bind("ID,Name,Continent,Foundation")] Country country) { if (ModelState.IsValid) { _context.Add(country); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(country)); }
public async Task <IActionResult> Create([Bind("ID,LastName,FirstName,BornDate,Height,Weight,CountryID")] Player player) { if (ModelState.IsValid) { _context.Add(player); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["CountryID"] = new SelectList(_context.Countries, "ID", "ID", player.CountryID); return(View(player)); }
public async Task <IActionResult> OnPostAsync() { var matchEntity = await GetMatchById(ResultModel.MatchId); matchEntity.Result = ResultModel.GetResult(); PointHistory pointHistory = new PointHistory { Id = Guid.NewGuid(), TimeStamp = DateTime.Now }; List <PointResult> results = new List <PointResult>(); foreach (var matchEntityBet in matchEntity.Bets) { List <PointPolicy> policies = new List <PointPolicy>(); foreach (var pointPolicy in PointPoliciese) { PointPolicy tmp = new PointPolicy { Applied = pointPolicy.CanApply(matchEntity.Result, matchEntityBet), Description = pointPolicy.Description, Name = pointPolicy.Name, Id = Guid.NewGuid(), Points = pointPolicy.Points, PolicyType = PolicyType.Match, TimeStamp = DateTime.Now }; policies.Add(tmp); } var user = await GetUserById(matchEntityBet.UserId); matchEntityBet.Result = new PointResult { User = user, Id = Guid.NewGuid(), AddedPoints = policies.Sum(c => c.Applied ? c.Points.Value : 0), PointPolicies = policies, SumPoints = user.Points + policies.Sum(c => c.Applied ? c.Points.Value : 0), TimeStamp = DateTime.Now }; user.Points = user.Points + policies.Sum(c => c.Applied ? c.Points.Value : 0); results.Add(matchEntityBet.Result); } pointHistory.PointResults = results; _context.PointHistories.Add(pointHistory); await _context.SaveChangesAsync(); return(RedirectToPage("../Dashboard/Index")); }
public async Task <IActionResult> OnPostAsync() { Match match = new Match { Date = Date, AwayTeam = _context.Teams.First(c => c.Id == AwayTeamId), HomeTeam = _context.Teams.First(c => c.Id == HomeTeamId) }; _context.Matches.Add(match); await _context.SaveChangesAsync(); return(RedirectToPage("../Dashboard/Index")); }
public async Task <bool> SaveAsync() { return(await _context.SaveChangesAsync() >= 0); }