Beispiel #1
0
        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"));
        }
Beispiel #2
0
 protected void OnSave(PointPolicy item)
 {
     this.AccountDependency.Save(item);
     item.AccountLevels = Levels == null ? "" : string.Join(",", this.Levels.GetCheckedIds().Select(x => x.ToString()).ToArray());
     item.Priority      = Priority;
 }
Beispiel #3
0
 protected void SetInnerObject(PointPolicy item)
 {
     _innerObject = item;
 }
Beispiel #4
0
 public PointPolicyModelBase(PointPolicy shop)
 {
     _innerObject = shop;
 }
Beispiel #5
0
 public PointPolicyModelBase()
 {
     _innerObject = new PointPolicy();
 }
Beispiel #6
0
 public EditPointPolicy(PointPolicy item)
     : base(item)
 {
 }
Beispiel #7
0
 public ListPointPolicy(PointPolicy adminUser)
 {
     _innerObject = adminUser;
 }
Beispiel #8
0
 public ListPointPolicy()
 {
     _innerObject = new PointPolicy();
 }