public AdminController(ShopDatabaseContext context)
 {
     this.db        = context;
     this.aProducts = new AProducts()
     {
         products       = db.Product.ToList(),
         choosenProduct = db.Product.Where(p => p.id == 0).FirstOrDefault()
     };
     pPageInfor  = new Models.Helpers.PagingInformation(aProducts.products.Count(), intialPage, pPageSize);
     this.aUsers = new AUsers()
     {
         customers = db.Customer.ToList(),
         addresses = db.Address.ToList(),
         comments  = db.Comment.ToList(),
     };
     this.aOrders = new AOrders()
     {
         orders        = db.Order,
         shoppingCarts = db.ShoppingCart,
         items         = db.Item,
         payments      = db.Payment
     };
     this.aAdmins = new AAdmins()
     {
         admins       = db.Admin,
         choosenAdmin = new Models.Admin(),
         editedAdmin  = new Models.Admin()
     };
     uPageInfor      = new Models.Helpers.PagingInformation(aUsers.customers.Count(), intialPage, uPageSize);
     this.aPromotion = new APromotion()
     {
         promotions       = db.Promotion,
         choosenPromotion = new Models.Promotion(),
         editedPromotion  = new Models.Promotion()
     };
     this.aNews = new ANews()
     {
         news        = db.News,
         choosenNews = new Models.News(),
         editedNews  = new Models.News()
     };
 }
        public IActionResult Products(AProducts aProduct)
        {
            Product product = new Product();

            product = aProduct.editedProduct;
            if (ModelState.IsValid)
            {
                if (aProduct.editedProduct != null && !String.IsNullOrEmpty(aProduct.editedProduct.name))
                {
                    if (aProduct.editedProduct.id == 0)
                    {
                        db.Product.Add(product);
                    }
                    else
                    {
                        Product pd = db.Product.FirstOrDefault();
                        db.Entry(pd).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                        db.SaveChanges();
                        db.Product.Update(product);
                    }
                }
                if (!String.IsNullOrEmpty(aProduct.editedSize.size))
                {
                    ProductSize size = aProduct.editedSize;
                    // size.product = this.aProducts.choosenProduct.id;
                    db.ProductSize.Add(size);
                    ViewBag.Id = aProduct.editedSize.size;
                }
            }

            db.SaveChanges();
            updateProductList(1, 0, "create");
            ModelState.Clear();

            // ViewBag.pName = aProduct.editedProduct.name;
            // ViewBag.Id=aProduct.editedProduct.id;
            ViewBag.totalPages = pPageInfor.totalPages;
            ViewBag.isCreation = this.isCreation ? "Create" : "Edit";

            return(View(this.aProducts));
        }