Example #1
0
        //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));
        }
Example #2
0
        // 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());
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        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));
        }
Example #6
0
        public IActionResult Index(string message)
        {
            if (message == null)
            {
                message = "";
            }
            ViewData["Message"] = message;
            FoodStoreContext db = new FoodStoreContext();

            return(View(db.Manufacturers.ToList()));
        }
Example #7
0
        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));
        }
Example #8
0
        // 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));
        }
Example #9
0
        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));
        }
Example #10
0
        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));
        }
Example #11
0
        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 }));
        }
Example #12
0
        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));
        }
Example #13
0
        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));
        }
Example #14
0
        // 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 }));
        }
Example #15
0
        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));
        }
Example #16
0
        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));
        }
Example #17
0
 public BuildingRepo(FoodStoreContext context)
 {
     db = context;
 }
Example #18
0
 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;
 }
Example #21
0
 public StoreBuildingVMController()
 {
     ctx    = new FoodStoreContext();
     sbRepo = new StoreBuildingVMRepo(ctx);
 }
Example #22
0
 public ProductController(FoodStoreContext db)
 {
     this.db = db;
 }
Example #23
0
 public StoresController(FoodStoreContext db)
 {
     _db = db;
 }
Example #24
0
 /// <summary>
 /// Public Constructor. Creates new food store context
 /// </summary>
 public EmployeeController()
 {
     _context = new FoodStoreContext();
 }
Example #25
0
 public EmployeeRepo(FoodStoreContext context)
 {
     db = context;
 }
Example #26
0
 /// <summary>
 /// Public Constructor. Creates for mocking tests.
 /// </summary>
 public EmployeeController(FoodStoreContext cont)
 {
     this._context = cont;
 }
Example #27
0
 public StoreRepo(FoodStoreContext context)
 {
     db = context;
 }
Example #28
0
 public StoreRepo(FoodStoreContext db)
 {
     this.db = db;
 }
Example #29
0
 public EmployeeRepo(FoodStoreContext db)
 {
     this.db = db;
 }
        /// <summary>
        /// Public constructor. Creates new food store context
        /// </summary>


        public ProductController()
        {
            _context = new FoodStoreContext();
        }