예제 #1
0
        private static void AddCutForPlayerForTargetRun(OmgSpidersDbContext ctx, SaleRun saleRun, string player, float cutValue)
        {
            var playerEntity = ctx.PlayerList.Single(x => x.PlayerName == player);

            ctx.SaleRunParticipation.Add(new SaleRunParticipation {
                RunId = saleRun.Id, PlayerId = playerEntity.Id, CutValue = cutValue
            });
        }
예제 #2
0
        public async Task <int> AddRunAsync(string title, long goldAmount, string[] playerAndCutEntryList)
        {
            for (int idx = 0; idx < playerAndCutEntryList.Length; ++idx)
            {
                playerAndCutEntryList[idx] = playerAndCutEntryList[idx].Trim();
            }

            using (var ctx = new OmgSpidersDbContext())
            {
                var saleRun = new SaleRun()
                {
                    RunName             = title,
                    GoldTotalAfterAdCut = goldAmount,
                    RunDate             = (DateTime?)DateTime.Now,
                    PlayerCount         = playerAndCutEntryList.Length
                };

                ctx.SaleRun.Add(saleRun);
                await ctx.SaveChangesAsync();

                saleRun = ctx.SaleRun.Single(
                    x => x.GoldTotalAfterAdCut == saleRun.GoldTotalAfterAdCut &&
                    x.RunName == saleRun.RunName &&
                    x.RunDate == saleRun.RunDate);

                this.AddNewPlayersNoCommit(playerAndCutEntryList, ctx);
                await ctx.SaveChangesAsync();

                // load the players we need now.
                AssignPlayerCuts(playerAndCutEntryList, ctx, saleRun);

                await ctx.SaveChangesAsync();

                return(saleRun.Id);
            }
        }
예제 #3
0
        private static void AssignPlayerCuts(string[] playerAndCutEntryList, OmgSpidersDbContext ctx, SaleRun saleRun)
        {
            var cutValue = 1.0f;

            for (var i = 0; i < playerAndCutEntryList.Length; i++)
            {
                var entry = playerAndCutEntryList[i];
                if (ShouldAddACutBecauseThisEntryIsNotAFloat(cutValue, out cutValue, entry))
                {
                    AddCutForPlayerForTargetRun(ctx, saleRun, entry, cutValue);
                }
            }
        }