Пример #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Listening for new messages...");

            var messageingService = new MessagingService();

            using (var context = new CheckoutContext())
            {
                context.Database.EnsureCreated();

                messageingService.ActivateMessageListener(ConfigurationDefaults.RABBITMQ_HOST, ConfigurationDefaults.RABBITMQ_EXCHANGENAME,
                                                          (nav) =>
                {
                    var navObject = JsonConvert.DeserializeObject <Navigation>(nav);
                    context.Navigations.Add(navObject);
                    context.SaveChanges();

                    Console.WriteLine($"MSG: {navObject.ToString()}");
                });

                while (Console.Read() != 13)
                {
                }

                messageingService.DeactivateMessageListener();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            using (var context = new CheckoutContext())
            {
                context.Products.Add(new Product
                {
                    Id           = Guid.NewGuid(),
                    Sku          = "A",
                    UnitPrice    = 9.99m,
                    Description  = "new product",
                    SpecialOffer = new SpecialOffer
                    {
                        Id          = Guid.NewGuid(),
                        IsAvailable = false
                    }
                });

                context.SaveChanges();

                var products = context.Products.ToList <Product>();
                foreach (var product in products)
                {
                    Console.WriteLine(product.Sku);
                }

                Console.WriteLine(@"Press any key.");
                Console.ReadLine();
            }
        }
Пример #3
0
        public CheckoutController(CheckoutContext context)
        {
            _context = context;

            if (_context.CheckoutItems.Count() == 0)
            {
                // Create a new CheckoutItem if collection is empty,
                // which means you can't delete all CheckoutItems.
                _context.CheckoutItems.Add(new CheckoutItem {
                    Name = "Juan Requeijo"
                });
                _context.SaveChanges();
            }
        }
Пример #4
0
 public bool Save()
 {
     return(Context.SaveChanges() > 0);
 }