示例#1
0
        public IActionResult News(ANews _news)
        {
            Models.News pro = new Models.News();
            pro = _news.editedNews;
            if (ModelState.IsValid)
            {
                if (pro != null)
                {
                    if (_news.editedNews.id == 0)
                    {
                        db.News.Add(pro);
                    }
                    else
                    {
                        Models.News pd = db.News.FirstOrDefault();
                        db.Entry(pd).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
                        db.SaveChanges();
                        db.News.Update(pro);
                    }
                }
            }

            db.SaveChanges();
            updateNewsList(1, "", "", 1);
            ModelState.Clear();

            // ViewBag.pName = aProduct.editedProduct.name;
            // ViewBag.Id=aProduct.editedProduct.id;
            ViewBag.isCreation = "Create";
            ViewBag.totalPage  = Math.Ceiling(this.aNews.news.Count() / (double)nPageSize);

            return(View(this.aNews));
        }
示例#2
0
 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()
     };
 }