Exemplo n.º 1
0
        public async Task <Game> CreateAsync(GameVm vm)
        {
            var now = DateTime.UtcNow;

            var newGame = new Game()
            {
                PlayerId  = vm.PlayerId,
                CreatedOn = now,
            };

            _dbcontext.Add(newGame);
            await _dbcontext.SaveChangesAsync();

            var dq2 = await _mapRepository.GetVmByNameAsync(null, "dq2");

            var newGameState = new GameState()
            {
                GameId      = newGame.Id,
                Timestamp   = now,
                Direction   = 0,
                MapId       = dq2.Id,
                MapXPrecise = dq2.Width / 2,
                MapYPrecise = dq2.Height / 2,
                MapX        = dq2.Width / 2,
                MapY        = dq2.Height / 2,
            };

            _dbcontext.Add(newGameState);
            await _dbcontext.SaveChangesAsync();

            return(newGame);
        }
Exemplo n.º 2
0
 public async Task <GameVm> Create(GameVm vm)
 {
     if (vm == null)
     {
         vm = new GameVm();
     }
     vm.PlayerId = PlayerId.Value;
     return(await _gameRepository.CreateVmAsync(vm));
 }
Exemplo n.º 3
0
        // GET: Games/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Game game = db.Games.Find(id);

            if (game == null)
            {
                return(HttpNotFound());
            }

            var payments = db.Payments.Where(c => c.GameId == id && !(new [] { PaymentUse.CashIn, PaymentUse.CashOut }.Contains(c.PaymentUse))).ToList();

            var vm = new GameVm()
            {
                Model = game,

                PlayerList = game.Players.Select(c =>
                                                 new GamePlayerListItem()
                {
                    Name  = c.Person.Name,
                    Input = string.Join(" + ", c.Payments.Where(s => s.PaymentUse == PaymentUse.CashIn).Select(s => s.Amount.ToString("0.##")).ToList()),
                    Out   = string.Join(" + ", c.Payments.Where(s => s.PaymentUse == PaymentUse.CashOut).Select(s => s.Amount.ToString("0.##")).ToList())
                }).ToList(),

                InputTotalAmount  = game.Players.SelectMany(c => c.Payments.Where(s => s.PaymentUse == PaymentUse.CashIn).Select(s => s.Amount)).Sum().ToString("0.##"),
                OutputTotalAmount = game.Players.SelectMany(c => c.Payments.Where(s => s.PaymentUse == PaymentUse.CashOut).Select(s => s.Amount)).Sum().ToString("0.##"),

                RakeList = game.Rakes.Select(c =>
                                             new GameRakeListItem()
                {
                    DateTime = c.DateTime.ToShortTimeString(),
                    Amount   = c.Amount.ToString("0.##"),
                    Diler    = c.Person.Name
                }).ToList(),
                RakeTotalAmount = game.Rakes.Sum(c => c.Amount).ToString("0.##"),

                SpendingList = payments.Select(c =>
                                               new GameSpendingListItem()
                {
                    Amount = c.Amount.ToString("0.##"),
                    Use    = c.AdditionInfo
                }).ToList(),
                SpendingTotalAmount = payments.Sum(c => c.Amount).ToString("0.##")
            };

            return(View(vm));
        }
Exemplo n.º 4
0
 public async Task <GameVm> CreateVmAsync(GameVm vm)
 => new GameVm(await CreateAsync(vm));
 public MainWindowVm()
 {
     Game = new GameVm(20, 20);
 }
Exemplo n.º 6
0
 public ApplicationVm()
 {
     RestartGameCommand = new RelayCommand(() => Game = new GameVm());
     RestartGameCommand.Execute(null);
 }