public IActionResult Promotion(APromotion promotion) { Models.Promotion pro = new Models.Promotion(); pro = promotion.editedPromotion; if (ModelState.IsValid) { if (pro != null) { if (promotion.editedPromotion.id == 0) { db.Promotion.Add(pro); } else { Models.Promotion pd = db.Promotion.FirstOrDefault(); db.Entry(pd).State = Microsoft.EntityFrameworkCore.EntityState.Detached; db.SaveChanges(); db.Promotion.Update(pro); } } } db.SaveChanges(); updatePromotionList(1, "", "", 1); ModelState.Clear(); // ViewBag.pName = aProduct.editedProduct.name; // ViewBag.Id=aProduct.editedProduct.id; ViewBag.isCreation = "Create"; ViewBag.totalPage = Math.Ceiling(this.aPromotion.promotions.Count() / (double)proPageSize); return(View(this.aPromotion)); }
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() }; }