//private readonly FoodStoreContext ctx; //public HomeController() //{ // ctx = new FoodStoreContext(); //} public IActionResult Index() { var ctx = new FoodStoreContext(); var products = from p in ctx.Products select p; return(View(products)); }
// GET: Home/Create public IActionResult Create() { FoodStoreContext db = new FoodStoreContext(); ViewData["Mfg"] = new SelectList(db.Manufacturers, "Mfg", "Mfg"); ViewData["Vendor"] = new SelectList(db.Suppliers, "Vendor", "Vendor"); return(View()); }
public IActionResult Details(string?branchName) { FoodStoreContext db = new FoodStoreContext(); Store store = (from s in db.Stores where s.Branch == branchName select s).FirstOrDefault(); return(View(store)); }
public IActionResult Details(int?id) { FoodStoreContext db = new FoodStoreContext(); var product = (from p in db.Products where p.ProductId == id select p).FirstOrDefault(); return(View(product)); }
public IActionResult Edit(string?mfg) { FoodStoreContext db = new FoodStoreContext(); Manufacturer manufacturer = (from m in db.Manufacturers where m.Mfg == mfg select m).FirstOrDefault(); return(View(manufacturer)); }
public IActionResult Index(string message) { if (message == null) { message = ""; } ViewData["Message"] = message; FoodStoreContext db = new FoodStoreContext(); return(View(db.Manufacturers.ToList())); }
public IActionResult Index() { FoodStoreContext db = new FoodStoreContext(); var stores = from s in db.Stores where s.Region == "BC" select s; var res = from s in stores.AsEnumerable() where Regex.IsMatch(s.Branch, "^(K|L|M)") == true select s; return(View(res)); }
// GET: Home/Edit public IActionResult Edit(int?id) { FoodStoreContext db = new FoodStoreContext(); var product = (from p in db.Products where p.ProductId == id select p).FirstOrDefault(); // This code is used to populate the Mfg and Vendor dropdowns. // the last parameter is the selected item for the product. ViewData["Mfg"] = new SelectList(db.Manufacturers, "Mfg", "Mfg", product.Mfg); ViewData["Vendor"] = new SelectList(db.Suppliers, "Vendor", "Vendor", product.Vendor); return(View(product)); }
public IActionResult Create([Bind("Mfg,MfgDiscount")] Manufacturer manufacturer) { FoodStoreContext db = new FoodStoreContext(); if (ModelState.IsValid) { db.Add(manufacturer); db.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["Mfg"] = manufacturer.Mfg; ViewData["MfgDiscount"] = manufacturer.MfgDiscount; return(View(manufacturer)); }
public IActionResult Create([Bind("ProductId,Name,Mfg,Vendor,Price")] Product product) { FoodStoreContext db = new FoodStoreContext(); // Ensure data is valid. if (ModelState.IsValid) { db.Add(product); db.SaveChanges(); // Save is successful so show updated listing. return(RedirectToAction(nameof(Index))); } // Data not valid so show form again with populated drop downs. ViewData["Mfg"] = new SelectList(db.Manufacturers, "Mfg", "Mfg", product.Mfg); ViewData["Vendor"] = new SelectList(db.Suppliers, "Vendor", "Vendor", product.Vendor); return(View(product)); }
public IActionResult Delete(string?mfg) { string deleteMessage = "Manufacturer : " + mfg + " deleted successfully"; try { FoodStoreContext db = new FoodStoreContext(); var manufacturer = (from m in db.Manufacturers where m.Mfg == mfg select m).FirstOrDefault(); db.Remove(manufacturer); db.SaveChanges(); } catch (Exception e) { deleteMessage = e.Message + " The product may not exist or there could be a foreign key restriction."; } return(RedirectToAction("Index", "Mfg", new { message = "** " + deleteMessage })); }
public IActionResult Edit([Bind("Mfg,MfgDiscount")] Manufacturer manufacturer) { ViewData["Message"] = ""; FoodStoreContext db = new FoodStoreContext(); if (ModelState.IsValid) { try { db.Update(manufacturer); db.SaveChanges(); ViewData["Message"] = "The update has been saved."; } catch (Exception ex) { ViewData["Message"] = ex.Message; } } return(View(manufacturer)); }
public IActionResult Index(string message) { if (message == null) { message = ""; } ViewData["Message"] = message; FoodStoreContext db = new FoodStoreContext(); // 1st query. var gfsItems = from p in db.Products where p.Vendor == "GFS" select p; // Second query using first query. var inexpesiveGFSItems = from p in gfsItems where p.Price < 2.50M select p; return(View(inexpesiveGFSItems)); }
// DELETE: Home/Delete public IActionResult Delete(int?id) { string deleteMessage = "Product Id: " + id + " deleted successfully"; try { FoodStoreContext db = new FoodStoreContext(); var product = (from p in db.Products where p.ProductId == id select p).FirstOrDefault(); db.Remove(product); db.SaveChanges(); } catch (Exception e) { deleteMessage = e.Message + " The product may not exist or there could be a foreign key restriction."; } // Redirects to Index action method of Home controller with message parameter. return(RedirectToAction("Index", "Home", new { message = "** " + deleteMessage })); }
public IActionResult Edit([Bind("ProductId,Name,Mfg,Vendor,Price")] Product product) { ViewData["Message"] = ""; FoodStoreContext db = new FoodStoreContext(); if (ModelState.IsValid) { try { db.Update(product); db.SaveChanges(); ViewData["Message"] = "The update has been saved."; } catch (Exception ex) { ViewData["Message"] = ex.Message; } } ViewData["Mfg"] = new SelectList(db.Manufacturers, "Mfg", "Mfg", product.Mfg); ViewData["Vendor"] = new SelectList(db.Suppliers, "Vendor", "Vendor", product.Vendor); return(View(product)); }
public IActionResult CustomerStoreBuilding() { var ctx = new FoodStoreContext(); // store employee buildling var employeeStore = from e in ctx.Employees from s in ctx.Stores where e.Branch == s.Branch select new EmployeeStoreVM() { LastName = e.LastName, FirstName = e.FirstName, Branch = e.Branch, Region = s.Region, BuildingName = s.BuildingName ?? "", UnitNum = s.UnitNum ?? 0 }; var esBuilding = from es in employeeStore from b in ctx.Buildings where es.BuildingName == b.BuildingName && es.UnitNum == b.UnitNum select new EmployeeStoreBuildingVM() { LastName = es.LastName, FirstName = es.FirstName, Branch = es.Branch, Region = es.Region, BuildingName = es.BuildingName, UnitNum = es.UnitNum, Capacity = b.Capacity }; return(View(esBuilding)); }
public BuildingRepo(FoodStoreContext context) { db = context; }
public StoreBuildingVMRepo(FoodStoreContext context) { db = context; }
/// <summary> /// Public constructor. Created for mocking tests /// </summary> public ProductController(FoodStoreContext cont) { this._context = cont; }
public ProductsController(FoodStoreContext context) { _context = context; }
public StoreBuildingVMController() { ctx = new FoodStoreContext(); sbRepo = new StoreBuildingVMRepo(ctx); }
public ProductController(FoodStoreContext db) { this.db = db; }
public StoresController(FoodStoreContext db) { _db = db; }
/// <summary> /// Public Constructor. Creates new food store context /// </summary> public EmployeeController() { _context = new FoodStoreContext(); }
public EmployeeRepo(FoodStoreContext context) { db = context; }
/// <summary> /// Public Constructor. Creates for mocking tests. /// </summary> public EmployeeController(FoodStoreContext cont) { this._context = cont; }
public StoreRepo(FoodStoreContext context) { db = context; }
public StoreRepo(FoodStoreContext db) { this.db = db; }
public EmployeeRepo(FoodStoreContext db) { this.db = db; }
/// <summary> /// Public constructor. Creates new food store context /// </summary> public ProductController() { _context = new FoodStoreContext(); }