// GET: T_PROD public ActionResult Index() { //return View(await db.T_PROD.ToListAsync()); using (SPOSEntities db = new SPOSEntities()) { List <T_SubCategory> subCategories = db.T_SubCategory.ToList(); List <T_Category> categories = db.T_Category.ToList(); List <T_PROD> products = db.T_PROD.ToList(); var subcategory = (from s in subCategories join c in categories on s.CategoryID equals c.CategoryID into table1 from c in table1.ToList() join p in products on s.CategoryID equals p.CategoryID into table2 from p in table2.ToList() where p.SubCategoryID == s.SubCategoryID select new ViewModel { SubCategories = s, Categories = c, Products = p }).OrderBy(x => x.Products.ProductID); return(View(subcategory)); } }
// GET: T_PROD/Create public ActionResult Create() { SPOSEntities entities = new SPOSEntities(); ViewModel model = new ViewModel(); foreach (var category in entities.T_Category) { model.PT_Category.Add(new SelectListItem { Text = category.CategoryName, Value = category.CategoryID.ToString() }); } return(View(model)); }
// GET: T_SubCategory public ActionResult Index() { using (SPOSEntities db = new SPOSEntities()) { List <T_SubCategory> subCategories = db.T_SubCategory.ToList(); List <T_Category> categories = db.T_Category.ToList(); var subcategory = from s in subCategories join c in categories on s.CategoryID equals c.CategoryID into table1 from c in table1.ToList() select new ViewModel { SubCategories = s, Categories = c }; return(View(subcategory)); } }
public async Task <ActionResult> Create([Bind(Include = "ProductID,CategoryID,SubCategoryID,PBarcode,PName,CostPrice,SalePrice,Discount,ReorderLevel,Manufacture,UnitID,IUser,EUser,IDate,EDate,IsRemoved,SalingPrice")] ViewModel viewModel, int?categoryID, int?SubCategoryID) { ViewModel model = new ViewModel(); SPOSEntities entities = new SPOSEntities(); foreach (var category in entities.T_Category) { model.PT_Category.Add(new SelectListItem { Text = category.CategoryName, Value = category.CategoryID.ToString() }); } if (categoryID.HasValue) { var T_SubCategory = (from subcategory in entities.T_SubCategory where subcategory.CategoryID == categoryID.Value select subcategory).ToList(); foreach (var subcategory in T_SubCategory) { model.PT_SubCategory.Add(new SelectListItem { Text = subcategory.SubCategoryName, Value = subcategory.SubCategoryID.ToString() }); } } if (ModelState.IsValid && SubCategoryID.HasValue) { viewModel.Products.CategoryID = categoryID.Value; viewModel.Products.SubCategoryID = SubCategoryID.Value; db.T_PROD.Add(viewModel.Products); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }