public async Task <ActionResult> Create() { SubCategoryCreateEditViewModel model = new SubCategoryCreateEditViewModel(); model.AllCategories = await db.Categories.ToListAsync(); await this.FillViewBag(); ViewBag.DefaultIMG = Url.Content("/Content/icons/DefaultSubCategory.png"); return(View(model)); }
public async Task <ActionResult> Edit(int?SubCategoryID) { if (SubCategoryID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SubCategoryModel subCategoryModel = await db.SubCategories.FindAsync(SubCategoryID); if (subCategoryModel == null) { return(HttpNotFound()); } SubCategoryCreateEditViewModel model = new SubCategoryCreateEditViewModel(); model.SubCategoryID = subCategoryModel.SubCategoryID; model.SubCategoryLogo = subCategoryModel.SubCategoryLogo; model.SubCategoryName = subCategoryModel.SubCategoryName; model.ParentCategories = subCategoryModel.ParentCategories.ToList(); model.AllCategories = await db.Categories.ToListAsync(); List <CategoryModel> tmpLst = new List <CategoryModel>(); foreach (CategoryModel cm in model.AllCategories) { foreach (CategoryModel pc in model.ParentCategories) { if (cm.CategoryID == pc.CategoryID) { tmpLst.Add(cm); break; } } } foreach (CategoryModel tcm in tmpLst) { model.AllCategories.Remove(tcm); } await this.FillViewBag(); ViewBag.DefaultIMG = Url.Content("/Content/icons/DefaultSubCategory.png"); return(View(model)); }