public ActionResult Create([Bind(Include = "ProductID,ProductName,MovieDescription,Price,NrInStore,Rating,ProductTypeID,Category")] FullProductAndCategoriesModel dataModel) { Products products = new Products() { ProductID = dataModel.ProductID, ProductName = dataModel.ProductName, MovieDescription = dataModel.MovieDescription, Price = dataModel.Price, NrInStore = dataModel.NrInStore, Rating = dataModel.Rating, ProductTypeID = dataModel.ProductTypeID }; if (ModelState.IsValid) { List <Categories> categories = new List <Categories>(dataModel.Category); db.Products.Add(products); foreach (var cat in dataModel.Category) { ProdCat prodCat = new ProdCat() { ProductID = products.ProductID, CategoryID = cat.CategoryID }; db.ProdCat.Add(prodCat); } db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductTypeID = new SelectList(db.ProductType, "ProductTypeID", "ProductTypeName", products.ProductTypeID); return(View(products)); }
public ActionResult DeleteConfirmed(int id) { ProdCat prodCat = db.ProdCat.Find(id); db.ProdCat.Remove(prodCat); db.SaveChanges(); return(RedirectToAction("Index")); }
public Software(string softName, SoftCat softCateg, OSTypeCat osCateg, int prodId, ProdCat prodCat, double unitPrice, int supplId, int qtyOnHand, bool prodStat) : base(prodId, softName, prodCat, unitPrice, supplId, qtyOnHand, prodStat) { this.ProdName = softName; this.SoftCateg = softCateg; this.OsCateg = osCateg; }
public Book(string bookISBN, string bookTitle, int yearReleased, BookCateg bookCat, List <Author> listAuthors, int prodId, ProdCat prodCat, double unitPrice, int supplId, int qtyOnHand, bool prodStat) : base(prodId, bookTitle, prodCat, unitPrice, supplId, qtyOnHand, prodStat) { this.BookISBN = bookISBN; this.BookTitle = bookTitle; this.YearReleased = yearReleased; this.BookCat = bookCat; this.ListAuthors = listAuthors; }
public Product(int prodId, string prodName, ProdCat prodCat, double unitPrice, int supplId, int qtyOnHand, bool prodStatus) { this.ProdId = prodId; this.ProdName = prodName; this.ProdCat = prodCat; this.UnitPrice = unitPrice; this.SupplId = supplId; this.QtyOnHand = qtyOnHand; this.ProdStatus = prodStatus; }
public ActionResult Edit([Bind(Include = "ProdCatID,ProductID,CategoryID")] ProdCat prodCat) { if (ModelState.IsValid) { db.Entry(prodCat).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", prodCat.CategoryID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", prodCat.ProductID); return(View(prodCat)); }
// GET: ProdCats/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProdCat prodCat = db.ProdCat.Find(id); if (prodCat == null) { return(HttpNotFound()); } return(View(prodCat)); }
// GET: ProdCats/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProdCat prodCat = db.ProdCat.Find(id); if (prodCat == null) { return(HttpNotFound()); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", prodCat.CategoryID); ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", prodCat.ProductID); return(View(prodCat)); }
public IActionResult Associate(ViewModel data) { ProdCat assoc = data.Association; if (ModelState.IsValid) { dbContext.Add(assoc); dbContext.SaveChanges(); // to pass parameters thru, create anonymous objects like below: return(RedirectToAction("Category", new { id = assoc.CatId })); } else { return(View("Category")); } }
public IActionResult AddCategory(int id, int category) { var pc = dbContext.ProductCategory .Where(p => p.ProductId == id); foreach (var p in pc) { if (p.CategoryId == category) { return(RedirectToAction("Products")); } } var prodCat = new ProdCat { ProductId = id, CategoryId = category }; dbContext.Add(prodCat); dbContext.SaveChanges(); return(RedirectToAction("Products")); }
public IActionResult AddCategory(Category category, int id, int product) { var pc = dbContext.ProductCategory .Where(c => c.CategoryId == id); foreach (var p in pc) { if (p.ProductId == product) { return(RedirectToAction("Products")); } } var prodCat = new ProdCat { ProductId = product, CategoryId = id }; dbContext.Add(prodCat); dbContext.SaveChanges(); return(RedirectToAction("categories")); }