public ActionResult editCat(int?id) { edit_category_vm catVM = new edit_category_vm(); if (id == null) { message = "Your Action is Wrong"; } else { category_tbl cat_tbl = db.category_tbl.Find(id); if (cat_tbl == null) { message = "No Data Found"; } else { catVM.serial = cat_tbl.category_id; catVM.CategoryName = cat_tbl.cat_name; catVM.LogoV = cat_tbl.logo; catVM.BannerV = cat_tbl.banner; catVM.parentID = cat_tbl.parent_id; catVM.top_cat = cat_tbl.top_cat; catVM.sort_order = cat_tbl.sort_order; catVM.status = cat_tbl.status; catVM.videoLink = cat_tbl.VideoLink; ViewBag.parentCat = new SelectList(db.category_tbl.ToList(), "category_id", "cat_name"); return(PartialView(catVM)); } } TempData["Message"] = message; return(RedirectToAction("manageCat")); }
public ActionResult editCat(edit_category_vm cat, HttpPostedFileBase logo, HttpPostedFileBase banner) { string path = ""; category_tbl cat_tbl = new category_tbl(); if (cat.CategoryName != null) { cat_tbl = db.category_tbl.Find(cat.serial); if (cat.logo != null && cat_tbl.logo != cat.logo.FileName) { if (cat_tbl.logo != null) { string fullPath = Request.MapPath("~/AppFiles/Cat/" + cat_tbl.logo); if (System.IO.File.Exists(fullPath)) { try { System.IO.File.Delete(fullPath); } catch (Exception e) { //Debug.WriteLine(e.Message); } } } //delete logo form system fileFolder //save the new logo string fileName = Path.GetFileNameWithoutExtension(logo.FileName); string extension = Path.GetExtension(logo.FileName); fileName = "L" + cat.serial + extension; fileName = fileName.Replace(" ", "-"); path = fileName; string savePath = Server.MapPath("~/AppFiles/Cat/"); logo.SaveAs(Path.Combine(savePath, fileName)); cat_tbl.logo = path; }// manage cat logo if (cat.banner != null && cat_tbl.banner != cat.banner.FileName) { if (cat_tbl.banner != null) { string fullPath = Request.MapPath("~/AppFiles/Cat/" + cat_tbl.banner); if (System.IO.File.Exists(fullPath)) { try { System.IO.File.Delete(fullPath); } catch (Exception e) { //Debug.WriteLine(e.Message); } } }//delete the banner form filefolder string fileName = Path.GetFileNameWithoutExtension(banner.FileName); string extension = Path.GetExtension(banner.FileName); fileName = "B" + cat.serial + extension; fileName = fileName.Replace(" ", "-"); path = fileName; string savePath = Server.MapPath("~/AppFiles/Cat/"); banner.SaveAs(Path.Combine(savePath, fileName)); cat_tbl.banner = path; } cat_tbl.category_id = cat.serial; cat_tbl.cat_name = cat.CategoryName; cat_tbl.date_modified = DateTime.Now; cat_tbl.Entry_by = User.Identity.GetUserId(); cat_tbl.parent_id = cat.parentID; cat_tbl.sort_order = cat.sort_order; cat_tbl.status = cat.status; cat_tbl.top_cat = cat.top_cat; cat_tbl.VideoLink = cat.videoLink; db.Entry(cat_tbl).State = EntityState.Modified; db.SaveChanges(); message = "Category Updated Successfully"; status = true; } else { message = "Thare have some problems.try agine"; } TempData["Status"] = status; TempData["Message"] = message; return(RedirectToAction("manageCat")); }