public ActionResult CatEditPost(int id, string name, int pid) { if (id > 0) { St_cat aCat = DBService.GetEntity <St_cat>(id); aCat.Name = name; string oldpath = aCat.Path; if (aCat.PId != pid && pid > 0) { var pcat = DBService.GetEntity <St_cat>(pid); if (pcat != null && pcat.Id > 0 && !pcat.Path.StartsWith(aCat.Path)) { aCat.PId = pid; aCat.Path = string.IsNullOrEmpty(pcat.Path) ? "," : pcat.Path + id.ToString() + ","; var pa = aCat.Path.Split(','); if (pa.Length > 3) { aCat.Level = pa.Length - 3; } else { aCat.Level = 0; } StockService.UpdateSubCatPath(id, oldpath, aCat.Path); } } DBService.UpdateEntity <St_cat>(aCat); StockService.UpdateCatPath(id, aCat.Path); } return(RedirectToAction("Cat")); }
public ActionResult CatAddPost(string name, int pid) { if (!string.IsNullOrEmpty(name)) { St_cat aCat = new St_cat(); aCat.Name = name; aCat.PId = pid; aCat.Level = 0; int lid = DBService.AddEntity <St_cat>(aCat, true); string catpath = ""; if (pid > 0) { var pcat = DBService.GetEntity <St_cat>(pid); if (pcat != null && pcat.Id > 0) { catpath = string.IsNullOrEmpty(pcat.Path) ? "," : pcat.Path + lid.ToString() + ","; } } else { catpath = "," + lid.ToString() + ","; } //aCat.Path = catpath; StockService.UpdateCatPath(lid, catpath); } return(RedirectToAction("Cat")); }