public async Task ProductContrAdd()
        {
            using (var contex = new ProdContext(options))
            {
                var     control = new ProductController(contex);
                Product newUom  = new Product {
                    Title = "Яблоки", UomId = 2
                };
                var result = await control.Post(newUom);

                var okResult = result.Result as OkObjectResult;
                Assert.Equal(newUom, okResult.Value);
                Assert.Equal(200, okResult.StatusCode);
            }
        }
예제 #2
0
        public async Task MovementsContrAdd()
        {
            using (var contex = new ProdContext(options))
            {
                var control             = new MovementsController(contex);
                ProductMovements newUom = new ProductMovements {
                    ProductId = 2, Quantity = -50
                };
                var result = await control.Post(newUom);

                var okResult = result.Result as OkObjectResult;
                Assert.Equal(newUom, okResult.Value);
                Assert.Equal(200, okResult.StatusCode);
            }
        }
        public ProductControllerTest()
        {
            options = new DbContextOptionsBuilder <ProdContext>()
                      .UseInMemoryDatabase(databaseName: "productsdb")
                      .Options;

            var context = new ProdContext(options);

            if (!context.Prod.Any())
            {
                using (context)
                {
                    context.Prod.Add(new Product
                    {
                        Title = "Бананы", UomId = 2
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Специи", UomId = 1
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Мандарины", UomId = 2
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Авокадо", UomId = 3
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Апельсины", UomId = 2
                    });

                    context.Prod.Add(new Product
                    {
                        Title = "Груши", UomId = 2
                    });
                    context.SaveChanges();
                }
            }
        }
예제 #4
0
        public UomController(ProdContext context)
        {
            db = context;
            if (!db.ProductUoms.Any())
            {
                db.ProductUoms.Add(new ProductUom {
                    Title = "шт"
                });
                db.ProductUoms.Add(new ProductUom {
                    Title = "г"
                });
                db.ProductUoms.Add(new ProductUom {
                    Title = "кг"
                });

                db.SaveChanges();
            }
        }
예제 #5
0
        public async Task UomContrPageSizeTest()
        {
            using (var context = new ProdContext(options))
            {
                UomController control = new UomController(context);
                var           result  = await control.Get(2, 3);

                var actualResult = result.Result;
                var productUoms  = new ProductUom {
                    Id = 4, Title = "т"
                };

                foreach (var x in result.Value)
                {
                    Assert.Equal(productUoms.Id, x.Id);
                    Assert.Equal(productUoms.Title, x.Title);
                }
            }
        }
        public ProductController(ProdContext context)
        {
            db = context;
            if (!db.Prod.Any())
            {
                db.Prod.Add(new Product {
                    Title = "Бананы", UomId = 3
                });
                db.Prod.Add(new Product {
                    Title = "Специи", UomId = 2
                });
                db.Prod.Add(new Product {
                    Title = "Мандарины", UomId = 3
                });
                db.Prod.Add(new Product {
                    Title = "Авокадо", UomId = 1
                });

                db.SaveChanges();
            }
        }
예제 #7
0
        public MovementsControllerTest()
        {
            options = new DbContextOptionsBuilder <ProdContext>()
                      .UseInMemoryDatabase(databaseName: "productsdb")
                      .Options;

            var context = new ProdContext(options);

            if (!context.Movements.Any())
            {
                using (context)
                {
                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 1, Quantity = 10
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 2, Quantity = 100
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 3, Quantity = 145
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 4, Quantity = 134
                    });

                    context.Movements.Add(new ProductMovements
                    {
                        ProductId = 1, Quantity = -2
                    });
                    context.SaveChanges();
                }
            }
        }
 public MovementsController(ProdContext context)
 {
     db = context;
     if (!db.Movements.Any())
     {
         db.Movements.Add(new ProductMovements {
             ProductId = 1, Quantity = 10
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 2, Quantity = 100
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 3, Quantity = 145
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 4, Quantity = 134
         });
         db.Movements.Add(new ProductMovements {
             ProductId = 1, Quantity = -2
         });
         db.SaveChanges();
     }
 }
예제 #9
0
 public AddCustomerForm()
 {
     this.db = new ProdContext();
     InitializeComponent();
 }
    private ExprContext expr(int _p)
    {
        ParserRuleContext _parentctx = Context;
        int         _parentState     = State;
        ExprContext _localctx        = new ExprContext(Context, _parentState);
        ExprContext _prevctx         = _localctx;
        int         _startState      = 0;

        EnterRecursionRule(_localctx, 0, RULE_expr, _p);
        int _la;

        try {
            int _alt;
            EnterOuterAlt(_localctx, 1);
            {
                State = 9;
                ErrorHandler.Sync(this);
                switch (TokenStream.LA(1))
                {
                case OP:
                {
                    _localctx = new ParenExpContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;

                    State = 3; Match(OP);
                    State = 4; expr(0);
                    State = 5; Match(CP);
                }
                break;

                case VAR:
                {
                    _localctx = new VarContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 7; Match(VAR);
                }
                break;

                case NUM:
                {
                    _localctx = new ConstContext(_localctx);
                    Context   = _localctx;
                    _prevctx  = _localctx;
                    State     = 8; Match(NUM);
                }
                break;

                default:
                    throw new NoViableAltException(this);
                }
                Context.Stop = TokenStream.LT(-1);
                State        = 24;
                ErrorHandler.Sync(this);
                _alt = Interpreter.AdaptivePredict(TokenStream, 3, Context);
                while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                {
                    if (_alt == 1)
                    {
                        if (ParseListeners != null)
                        {
                            TriggerExitRuleEvent();
                        }
                        _prevctx = _localctx;
                        {
                            State = 22;
                            ErrorHandler.Sync(this);
                            switch (Interpreter.AdaptivePredict(TokenStream, 2, Context))
                            {
                            case 1:
                            {
                                _localctx = new PowerContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 11;
                                if (!(Precpred(Context, 5)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 5)");
                                }
                                State = 12; Match(POWER);
                                State = 13; expr(5);
                            }
                            break;

                            case 2:
                            {
                                _localctx = new ProdContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 14;
                                if (!(Precpred(Context, 4)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 4)");
                                }
                                State = 16;
                                ErrorHandler.Sync(this);
                                _la = TokenStream.LA(1);
                                if (_la == PROD)
                                {
                                    {
                                        State = 15; Match(PROD);
                                    }
                                }

                                State = 18; expr(5);
                            }
                            break;

                            case 3:
                            {
                                _localctx = new PlusminusContext(new ExprContext(_parentctx, _parentState));
                                PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                State = 19;
                                if (!(Precpred(Context, 3)))
                                {
                                    throw new FailedPredicateException(this, "Precpred(Context, 3)");
                                }
                                State = 20;
                                _la   = TokenStream.LA(1);
                                if (!(_la == PLUS || _la == MINUS))
                                {
                                    ErrorHandler.RecoverInline(this);
                                }
                                else
                                {
                                    ErrorHandler.ReportMatch(this);
                                    Consume();
                                }
                                State = 21; expr(4);
                            }
                            break;
                            }
                        }
                    }
                    State = 26;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 3, Context);
                }
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            UnrollRecursionContexts(_parentctx);
        }
        return(_localctx);
    }
예제 #11
0
 public AddOrder()
 {
     this.db = new ProdContext();
     InitializeComponent();
 }
 public CustomersController()
 {
     ProdContext = new ProdContext();
 }
 public CategoriesController()
 {
     ProdContext = new ProdContext();
 }
예제 #14
0
 public ProductsController()
 {
     ProdContext = new ProdContext();
 }
예제 #15
0
 public CategoriesController(ProdContext context)
 {
     _context = context;
 }
 public ProdutoesController(ProdContext context)
 {
     _context = context;
 }
 public OrdersController()
 {
     ProdContext = new ProdContext();
 }
예제 #18
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Form categoryForm = new CategoryForm();
            Form orderForm    = new OrderForm();

            using (var db = new ProdContext())
            {
                //Console.Write("Enter a name for a new Category:");
                //var name = Console.ReadLine();

                //var category = new Category { Name = name };
                // db.Categories.Add(category);
                //db.SaveChanges();


                // Display all Categories from the database
                //var query = from c in db.Categories
                //            orderby c.Name
                //            descending
                //            select c;


                //Method based lazy:
                // IEnumerable<Category> query2 = db.Categories.OrderByDescending(c => c.Name);

                //Method based eager:
                //IEnumerable<Category> query3 = db.Categories.OrderByDescending(c => c.Name).ToList();

                // Console.WriteLine("All categories in the database:");
                // foreach (var item in query2)
                // {
                //     Console.WriteLine("{0}", item.Name );
                // }

                //Console.WriteLine("All categories in the database:");
                //foreach (var item in query3)
                //{
                //    Console.WriteLine("{0}", item.Name);
                //}


                // Console.WriteLine("Press any key to exit...");
                //Console.ReadKey();



                //-----------------------------------------------------------------------------------------------
                //METODY, KAŻDA W DWOCH WERSJACH

                //Pobiorą i wyświetlą wszystkie kategorie i produkty wykorzystujac:

                //1. Join -----------------
                //Query
                var join_query = from c in db.Categories
                                 join p in db.Products on c.CategoryID equals p.CategoryID
                                 into products
                                 select new
                {
                    CatName  = c.Name,
                    Products = products
                };
                //Method
                var method_join_query = db.Categories
                                        .GroupJoin(db.Products,
                                                   c => c.CategoryID,
                                                   p => p.CategoryID,
                                                   (c, p) => new
                {
                    CatID    = c.CategoryID,
                    CatName  = c.Name,
                    Products = db.Products.Where(x => x.CategoryID == c.CategoryID).ToList()
                });


                //  Console.WriteLine("All categories and products in the database:");
                //  foreach (var item in method_join_query)
                //  {
                //     Console.WriteLine("{0}:", item.CatName);
                //      foreach (var prod in item.Products)
                //      {
                //          Console.WriteLine("{0}", prod.Name);
                //      }
                //     Console.WriteLine("\n");
                //  }
                //     Console.WriteLine("Press any key to exit...");
                //     Console.ReadKey();



                //Navigation Properties---------------------------------------
                var navigationQuery1 = from c in db.Categories
                                       select new
                {
                    CatName = c.Name,
                    Prods   = c.Products
                };


                //Lazy vs Eager-----------------------------------------------
                //Lazy:
                //Query
                var join_query2 = (from c in db.Categories
                                   join p in db.Products on c.CategoryID equals p.CategoryID
                                   into products
                                   select new
                {
                    CatName = c.Name,
                    Products = products
                });

                //method
                var method_join_query2 = db.Categories
                                         .GroupJoin(db.Products,
                                                    c => c.CategoryID,
                                                    p => p.CategoryID,
                                                    (c, p) => new
                {
                    CatName  = c.Name,
                    Products = db.Products.Where(x => x.CategoryID == c.CategoryID).ToList()
                });



                //Eager:
                //Query
                var join_query3 = (from c in db.Categories.Include("Products")
                                   join p in db.Products on c.CategoryID equals p.CategoryID
                                   into products
                                   select new
                {
                    CatName = c.Name,
                    Products = products
                }).ToList();

                //method
                var method_join_query3 = db.Categories.Include(c => c.Products)
                                         .GroupJoin(db.Products,
                                                    c => c.CategoryID,
                                                    p => p.CategoryID,
                                                    (c, p) => new
                {
                    CatName  = c.Name,
                    Products = db.Products.Where(x => x.CategoryID == c.CategoryID).ToList()
                }).ToList();



                //2. Dla każdej kategorii pokaza ilość produktów---------------------------
                //a) Query
                var count_join_query = from c in db.Categories
                                       join p in db.Products on c.CategoryID equals p.CategoryID
                                       into res
                                       select new
                {
                    CatName = c.Name,
                    Count   = res.Count()
                };


                //b) Method
                var count_method_join_query = db.Categories
                                              .GroupJoin(db.Products,
                                                         c => c.CategoryID,
                                                         p => p.CategoryID,
                                                         (c, p) => new
                {
                    CatName = c.Name,
                    Count   = c.Products.Count()
                }).Distinct().OrderByDescending(x => x.Count);


                Console.WriteLine("All categories in the database:");
                foreach (var item in count_join_query)
                {
                    Console.WriteLine("{0}\t{1}", item.CatName, item.Count);
                }



                //categoryForm.ShowDialog();
                orderForm.ShowDialog();
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();

                //Console.WriteLine("Press any key to exit...");
                //Console.ReadKey();
            }
        }