コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: AddResult.cshtml.cs プロジェクト: szymo0/WorldCup
        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"));
        }
コード例 #4
0
ファイル: Add.cshtml.cs プロジェクト: szymo0/WorldCup
        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"));
        }
コード例 #5
0
 public async Task <bool> SaveAsync()
 {
     return(await _context.SaveChangesAsync() >= 0);
 }