public VendingMachineViewModel Ask()
        {
            using (var dbContext = new VendingMachineDbContext())
            {
                var vMachine = dbContext.Set<VendingMachineEntity>().Single();
                var buyer = dbContext.Set<UserEntity>().Single();
                var vMachineWallet = vMachine.Coins
                    .Select(c => new CoinViewModel
                    {
                        ParValue = c.FaceValue,
                        Count = c.Count
                    }).ToList();
                var buyerWallet = buyer.Coins
                    .Select(c => new CoinViewModel
                    {
                        ParValue = c.FaceValue,
                        Count = c.Count
                    }).ToList();
                var availableGoods = vMachine.Goods
                    .Select(g => new GoodsViewModel
                    {
                        Identity = g.Id,
                        Name = g.Name,
                        Price = g.Price,
                        Count = g.Count
                    }).ToList();

                return new VendingMachineViewModel
                {
                    AvailableGoods = availableGoods,
                    BuyerWallet = buyerWallet,
                    MachineWallet = vMachineWallet
                };
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var containerBuilder = new ContainerBuilder();
            containerBuilder.RegisterModule<CompositionRoot>();
            var container = containerBuilder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            var dbContext = new VendingMachineDbContext();
            dbContext.Database.Initialize(false);
        }
Exemple #3
0
 public CoinsRefundedEventCommitter(VendingMachineDbContext dbContext) : base(dbContext)
 {
 }
 public GoodsBuyedEventCommitter(VendingMachineDbContext dbContext) : base(dbContext)
 {
 }