public ActionResult Index() { TrentBasDbContext db = new TrentBasDbContext(); List <Product> products = db.Products.ToList(); return(View(products)); }
public Category GetCategoriesByCategoryID(long CategoryID) { TrentBasDbContext db = new TrentBasDbContext(); Category existingCategory = db.Categories.Where(b => b.CategoryID == CategoryID).FirstOrDefault(); return(existingCategory); }
public void PostBrand(Brand newBrand) { TrentBasDbContext db = new TrentBasDbContext(); db.Brands.Add(newBrand); db.SaveChanges(); }
public List <Category> Get() { TrentBasDbContext db = new TrentBasDbContext(); List <Category> categories = db.Categories.ToList(); return(categories); }
public Brand GetBrandsByBrandID(long BrandID) { TrentBasDbContext db = new TrentBasDbContext(); Brand existingBrand = db.Brands.Where(b => b.BrandID == BrandID).FirstOrDefault(); return(existingBrand); }
public List <Brand> Get() { TrentBasDbContext db = new TrentBasDbContext(); List <Brand> brands = db.Brands.ToList(); return(brands); }
public void DeleteBrand(long BrandID) { TrentBasDbContext db = new TrentBasDbContext(); Brand existingBrand = db.Brands.Where(b => b.BrandID == BrandID).FirstOrDefault(); db.Brands.Remove(existingBrand); db.SaveChanges(); }
public void PutBrand(Brand brandData) { TrentBasDbContext db = new TrentBasDbContext(); Brand existingBrand = db.Brands.Where(b => b.BrandID == brandData.BrandID).FirstOrDefault(); existingBrand.BrandName = brandData.BrandName; db.SaveChanges(); }
// GET: Admin/Categories public ActionResult Index() { TrentBasDbContext db = new TrentBasDbContext(); List <Category> categories = db.Categories.ToList(); return(View(categories)); }
public ActionResult Edit(Product p) { TrentBasDbContext db = new TrentBasDbContext(); Product existingProduct = db.Products.Where(prod => prod.ProductID == p.ProductID).FirstOrDefault(); if (ModelState.IsValid) { if (Request.Files.Count >= 1) { var file = Request.Files[0]; if (file.ContentLength >= 1) { var imgBytes = new Byte[file.ContentLength]; file.InputStream.Read(imgBytes, 0, file.ContentLength); var base64String = Convert.ToBase64String(imgBytes, 0, imgBytes.Length); existingProduct.Photo = base64String; } 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; prodService.UpdateT(existingProduct); } return(RedirectToAction("Index", "Products")); } else { return(View()); } }
// GET: Products public ActionResult Index(string search = "", string SortColumn = "ProductName", string IconClass = "fa-sort-asc", int PageNo = 1) { TrentBasDbContext db = new TrentBasDbContext(); ViewBag.search = search; List <Product> products = prodService.SearchT(search); ViewBag.SortColumn = SortColumn; ViewBag.IconClass = IconClass; if (ViewBag.SortColumn == "ProductID") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.ProductID).ToList(); } else { products = products.OrderByDescending(p => p.ProductID).ToList(); } } else if (ViewBag.SortColumn == "ProductName") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.ProductName).ToList(); } else { products = products.OrderByDescending(p => p.ProductName).ToList(); } } else if (ViewBag.SortColumn == "Price") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.Price).ToList(); } else { products = products.OrderByDescending(p => p.Price).ToList(); } } else if (ViewBag.SortColumn == "DateOfPurchase") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.DateOfPurchase).ToList(); } else { products = products.OrderByDescending(p => p.DateOfPurchase).ToList(); } } else if (ViewBag.SortColumn == "AvailabilityStatus") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.AvailabilityStatus).ToList(); } else { products = products.OrderByDescending(p => p.AvailabilityStatus).ToList(); } } else if (ViewBag.SortColumn == "CategoryID") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.Category.CategoryName).ToList(); } else { products = products.OrderByDescending(p => p.Category.CategoryName).ToList(); } } else if (ViewBag.SortColumn == "BrandID") { if (ViewBag.IconClass == "fa-sort-asc") { products = products.OrderBy(p => p.Brand.BrandName).ToList(); } else { products = products.OrderByDescending(p => p.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)); }
public ProductsController(ProductService ProductService) { this.db = new TrentBasDbContext(); this.prodService = ProductService; }