예제 #1
0
        public ActionResult Update(int id)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product existingProduct      = db.Products.Where(temp => temp.ProductID == id).FirstOrDefault();

            // db.SaveChanges();
            return(View(existingProduct));
        }
        public ActionResult Create(Product p)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            db.Products.Add(p);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create()
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            ViewBag.Categories = db.Categories.ToList();
            ViewBag.Brands     = db.Brands.ToList();
            return(View());
        }
예제 #4
0
        public ActionResult UpdateProduct(int?id)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product prodToUpdate         = db.Products.Where(s => s.ProductID == id).FirstOrDefault();

            ViewBag.Brands     = db.Brands.ToList();
            ViewBag.Categories = db.Categories.ToList();
            return(View(prodToUpdate));
        }
        public ActionResult Edit(long id)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product existingProduct      = db.Products.Where(temp => temp.ProductID == id).FirstOrDefault();

            ViewBag.Categories = db.Categories.ToList();
            ViewBag.Brands     = db.Brands.ToList();
            return(View(existingProduct));
        }
        public ActionResult Delete(long id, Product p)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product existingProduct      = db.Products.Where(temp => temp.ProductID == id).FirstOrDefault();

            db.Products.Remove(existingProduct);
            db.SaveChanges();
            return(RedirectToAction("Index", "Products"));
        }
예제 #7
0
        public ActionResult Delete(Product product)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product foundProduct         = db.Products.Where(p => p.ProductID == product.ProductID).FirstOrDefault();

            db.Products.Remove(foundProduct);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #8
0
        public ActionResult Edit(long id)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product product = db.Products.Where(p => p.ProductID == id).FirstOrDefault();

            product.Categories = db.Categories.ToList();
            product.Brands     = db.Brands.ToList();
            return(View(product));
        }
        // GET: Products/Index
        public ActionResult Index(string search = "")
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            ViewBag.search = search;
            List <Product> products = db.Products.Where(temp => temp.ProductName.Contains(search)).ToList();

            return(View(products));
        }
        public ActionResult Edit(Product p)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product existingProduct      = db.Products.Where(temp => temp.ProductID == p.ProductID).FirstOrDefault();

            existingProduct.ProductName        = p.ProductName;
            existingProduct.Price              = p.Price;
            existingProduct.DateOfPurchase     = p.DateOfPurchase;
            existingProduct.CategoryID         = p.CategoryID;
            existingProduct.BrandID            = p.BrandID;
            existingProduct.AvailabilityStatus = p.AvailabilityStatus;
            existingProduct.Active             = p.Active;
            db.SaveChanges();
            return(RedirectToAction("Index", "Products"));
        }
예제 #11
0
 public ActionResult Create(Product product)
 {
     try
     {
         EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
         db.Products.Add(product);
         db.SaveChanges();
         return(RedirectToAction("Index", "Products"));
     }
     catch (Exception e)
     {
         ViewBag.message = e;
         return(View(ViewBag.message));
     }
 }
        public ActionResult Create(Product p)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            if (Request.Files.Count >= 1)
            {
                var file     = Request.Files[0];
                var imgBytes = new Byte[file.ContentLength];
                file.InputStream.Read(imgBytes, 0, file.ContentLength);
                var base64String = Convert.ToBase64String(imgBytes, 0, imgBytes.Length);
                p.Photo = base64String;
            }
            db.Products.Add(p);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #13
0
        public ActionResult Edit(Product product)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product foundProduct         = db.Products.Where(p => p.ProductID == product.ProductID).FirstOrDefault();

            foundProduct.ProductName        = product.ProductName;
            foundProduct.Price              = product.Price;
            foundProduct.DateOfPurchase     = product.DateOfPurchase;
            foundProduct.AvailabilityStatus = product.AvailabilityStatus;
            foundProduct.CategoryID         = product.CategoryID;
            foundProduct.BrandID            = product.BrandID;
            foundProduct.Active             = product.Active;

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #14
0
        public ActionResult UpdateProduct(Product product)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
            Product exstingProduct       = db.Products.Where(s => s.ProductID == product.ProductID).FirstOrDefault();

            exstingProduct.ProductName        = product.ProductName;
            exstingProduct.Price              = product.Price;
            exstingProduct.DateOfPurchase     = product.DateOfPurchase;
            exstingProduct.AvailabilityStatus = product.AvailabilityStatus;
            exstingProduct.Active             = product.Active;
            exstingProduct.BrandID            = product.BrandID;
            exstingProduct.CategoryID         = product.CategoryID;


            db.SaveChanges();


            return(Redirect("/Products/Index"));
        }
예제 #15
0
        public ActionResult Create(Product prod)
        {
            Product p = new Product()
            {
                ProductID      = prod.ProductID,
                ProductName    = prod.ProductName,
                Price          = prod.Price,
                DateOfPurchase = prod.DateOfPurchase,
                Active         = prod.Active,
                BrandID        = prod.BrandID,
                CategoryID     = prod.CategoryID
            };

            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            db.Products.Add(p);
            db.SaveChanges();

            // List<Product> products = db.Products.ToList();
            return(Redirect("/Products/Index"));
        }
예제 #16
0
        // GET: Products
        public ActionResult Index(string Search = "", string SortColumn = "ProductName", string IconClass = "fa-sort-asc")
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            ViewBag.value = Search;
            List <Product> products = db.Products.Where(temp => temp.ProductName.Contains(Search)).ToList();

            ViewBag.SortColumn = SortColumn;
            ViewBag.IconClass  = IconClass;
            if (ViewBag.SortColumn == "ProductID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.ProductID).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.ProductID).ToList();
                }
            }

            return(View(products));
        }
예제 #17
0
        public ActionResult Edit(Product p)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            if (ModelState.IsValid)
            {
                Product existingProduct = db.Products.Where(temp => temp.ProductID == p.ProductID).FirstOrDefault();
                existingProduct.ProductName        = p.ProductName;
                existingProduct.Price              = p.Price;
                existingProduct.DateOfPurchase     = p.DateOfPurchase;
                existingProduct.CategoryID         = p.CategoryID;
                existingProduct.BrandID            = p.BrandID;
                existingProduct.AvailabilityStatus = p.AvailabilityStatus;
                existingProduct.Active             = p.Active;
                db.SaveChanges();
                return(RedirectToAction("Index", "Products"));
            }
            else
            {
                ViewBag.Categories = db.Categories.ToList();
                ViewBag.Brands     = db.Brands.ToList();
                return(View(db.Products.Where(temp => temp.ProductID == p.ProductID).FirstOrDefault()));
            }
        }
        // GET: Products/Index
        public ActionResult Index(string search = "", string SortColumn = "ProductName", string IconClass = "fa-sort-asc")
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            ViewBag.search = search;
            List <Product> products = db.Products.Where(temp => temp.ProductName.Contains(search)).ToList();

            /*Sorting*/
            ViewBag.SortColumn = SortColumn;
            ViewBag.IconClass  = IconClass;
            if (ViewBag.SortColumn == "ProductID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.ProductID).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.ProductID).ToList();
                }
            }
            else if (ViewBag.SortColumn == "ProductName")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.ProductName).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.ProductName).ToList();
                }
            }
            else if (ViewBag.SortColumn == "Price")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.Price).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.Price).ToList();
                }
            }
            else if (ViewBag.SortColumn == "DateOfPurchase")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.DateOfPurchase).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.DateOfPurchase).ToList();
                }
            }
            else if (ViewBag.SortColumn == "AvailabilityStatus")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.AvailabilityStatus).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.AvailabilityStatus).ToList();
                }
            }
            else if (ViewBag.SortColumn == "CategoryID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.Category.CategoryName).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.Category.CategoryName).ToList();
                }
            }
            else if (ViewBag.SortColumn == "BrandID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.Brand.BrandName).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.Brand.BrandName).ToList();
                }
            }

            return(View(products));
        }
예제 #19
0
 public ProductsRepository()
 {
     this.db = new EFDBFirstDatabaseEntities();
 }
        // GET: Products/Index
        public ActionResult Index(string search = "", string SortColumn = "ProductName", string IconClass = "fa-sort-asc", int PageNo = 1)
        {
            EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();

            ViewBag.search = search;
            List <Product> products = db.Products.Where(temp => temp.ProductName.Contains(search)).ToList();

            /*Sorting*/
            ViewBag.SortColumn = SortColumn;
            ViewBag.IconClass  = IconClass;
            if (ViewBag.SortColumn == "ProductID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.ProductID).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.ProductID).ToList();
                }
            }
            else if (ViewBag.SortColumn == "ProductName")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.ProductName).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.ProductName).ToList();
                }
            }
            else if (ViewBag.SortColumn == "Price")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.Price).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.Price).ToList();
                }
            }
            else if (ViewBag.SortColumn == "DateOfPurchase")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.DateOfPurchase).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.DateOfPurchase).ToList();
                }
            }
            else if (ViewBag.SortColumn == "AvailabilityStatus")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.AvailabilityStatus).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.AvailabilityStatus).ToList();
                }
            }
            else if (ViewBag.SortColumn == "CategoryID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.Category.CategoryName).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.Category.CategoryName).ToList();
                }
            }
            else if (ViewBag.SortColumn == "BrandID")
            {
                if (ViewBag.IconClass == "fa-sort-asc")
                {
                    products = products.OrderBy(temp => temp.Brand.BrandName).ToList();
                }
                else
                {
                    products = products.OrderByDescending(temp => temp.Brand.BrandName).ToList();
                }
            }

            /* Paging */
            int NoOfRecordsPerPage = 5;
            int NoOfPages          = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(products.Count) / Convert.ToDouble(NoOfRecordsPerPage)));
            int NoOfRecordsToSkip  = (PageNo - 1) * NoOfRecordsPerPage;

            ViewBag.PageNo    = PageNo;
            ViewBag.NoOfPages = NoOfPages;
            products          = products.Skip(NoOfRecordsToSkip).Take(NoOfRecordsPerPage).ToList();

            return(View(products));
        }