public async Task <ActionResult> DeleteConfirmed(long id) { bool chekIfSub = false; CategeogySubCategory categeogySubCategory = await db.CategeogySubCategories.FindAsync(id); if (categeogySubCategory.parentId != null && categeogySubCategory.parentId != 0) { chekIfSub = true; } //Remove spa mapping to selected category. db.spa_prices.RemoveRange(db.spa_prices.Where(x => x.CategeogySubCategory.id == categeogySubCategory.id)); //Remove spa mapping that are mapped to child category. List <long> childCat = db.CategeogySubCategories.Where(x => x.parentId == categeogySubCategory.id).Select(x => x.id).ToList(); db.spa_prices.RemoveRange(db.spa_prices.Where(x => childCat.Contains(x.cat_id))); //Remove child category db.CategeogySubCategories.RemoveRange(db.CategeogySubCategories.Where(x => x.parentId == categeogySubCategory.id)); //Remove category db.CategeogySubCategories.Remove(categeogySubCategory); await db.SaveChangesAsync(); if (chekIfSub) { return(RedirectToAction("SubCategory")); } return(RedirectToAction("Index")); }
// GET: Admin/CatSubCat/Edit/5 public async Task <ActionResult> Edit(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategeogySubCategory categeogySubCategory = await db.CategeogySubCategories.FindAsync(id); if (categeogySubCategory == null) { return(HttpNotFound()); } return(View(categeogySubCategory)); }
public async Task <ActionResult> Edit([Bind(Include = "id,parentId,name,subheading,description,isActive,created_at")] CategeogySubCategory categeogySubCategory, string Cat_SubCat) { if (ModelState.IsValid) { categeogySubCategory.updated_at = DateTime.Now; db.Entry(categeogySubCategory).State = EntityState.Modified; await db.SaveChangesAsync(); if (String.IsNullOrEmpty(Cat_SubCat)) { return(RedirectToAction("Index")); } return(RedirectToAction("SubCategory")); } return(View(categeogySubCategory)); }
// GET: Admin/CatSubCat/Delete/5 public async Task <ActionResult> Delete(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategeogySubCategory categeogySubCategory = await db.CategeogySubCategories.FindAsync(id); if (categeogySubCategory == null) { return(HttpNotFound()); } ViewBag.ParentName = ""; if (categeogySubCategory.parentId != null && categeogySubCategory.parentId != 0) { ViewBag.ParentName = db.CategeogySubCategories.Find(categeogySubCategory.parentId).name; } return(View(categeogySubCategory)); }
// GET: Admin/CatSubCat/Edit/5 public async Task <ActionResult> Edit_SubCat(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategeogySubCategory categeogySubCategory = await db.CategeogySubCategories.FindAsync(id); if (categeogySubCategory == null) { return(HttpNotFound()); } SelectList CategoryLst = new SelectList(db.CategeogySubCategories.Where(x => x.parentId == null).Select(a => new SelectListItem { Text = a.name, Value = SqlFunctions.StringConvert((double)a.id).Trim() }).ToList(), "Value", "Text"); ViewBag.CategoryList = CategoryLst; return(View("Edit_SubCat", categeogySubCategory)); }
public async Task <ActionResult> Create([Bind(Include = "id,parentId,name,subheading,description,isActive")] CategeogySubCategory categeogySubCategory, string Cat_SubCat) { if (ModelState.IsValid) { categeogySubCategory.created_at = DateTime.Now; categeogySubCategory.updated_at = DateTime.Now; db.CategeogySubCategories.Add(categeogySubCategory); await db.SaveChangesAsync(); if (String.IsNullOrEmpty(Cat_SubCat)) { return(RedirectToAction("Index")); } return(RedirectToAction("SubCategory")); } if (String.IsNullOrEmpty(Cat_SubCat)) { return(View(categeogySubCategory)); } return(View("Create_SubCat", categeogySubCategory)); }