public void GetChilds(List <Entity.CusCategory> oldData, List <Entity.CusCategory> newData, int?pid) { List <Entity.CusCategory> list = new List <Entity.CusCategory>(); if (pid == null) { list = oldData.Where(p => p.PID == null).ToList(); } else { list = oldData.Where(p => p.PID == pid).ToList(); } foreach (var item in list) { Entity.CusCategory entity = new Entity.CusCategory(); entity.AddTime = item.AddTime; entity.Depth = item.Depth; entity.ID = item.ID; entity.PID = item.PID; entity.SortNo = item.SortNo; entity.Status = item.Status; entity.Title = item.Title; newData.Add(entity); this.GetChilds(oldData, newData, item.ID); } }
/// <summary> /// 修改分类数据 /// </summary> /// <returns></returns> public static bool Modify(Entity.CusCategory entity) { if (entity == null) { return(false); } var db = new DataCore.EFDBContext(); Entity.CusCategory p_entity = null; if (entity.PID != null) { p_entity = db.CusCategorys.Find(entity.PID); if (p_entity == null) { entity.PID = null; entity.Depth = 1; } else { entity.Depth = p_entity.Depth + 1; } } db.Entry <Entity.CusCategory>(entity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); db.Dispose(); return(true); }
/// <summary> /// 添加分类数据 /// </summary> /// <returns></returns> public static int Add(Entity.CusCategory entity) { if (entity == null) { return(-1); } var db = new DataCore.EFDBContext(); Entity.CusCategory p_entity = null; if (entity.PID != null) { p_entity = db.CusCategorys.Find(entity.PID); if (p_entity == null) { entity.PID = null; entity.Depth = 1; } else { entity.Depth = p_entity.Depth + 1; } } db.CusCategorys.Add(entity); db.SaveChanges(); db.Dispose(); return(entity.ID); }
public ActionResult Edit(int?id) { BLL.BaseBLL <Entity.CusCategory> bll = new BLL.BaseBLL <Entity.CusCategory>(); LoadCategorySelect(); Entity.CusCategory entity = new Entity.CusCategory(); int num = TypeHelper.ObjectToInt(id, 0); if (num != 0) { entity = bll.GetModel(p => p.ID == num, null); if (entity == null) { return(PromptView("/admin/CusCategory", "404", "Not Found", "信息不存在或已被删除", 5)); } } return(View(entity)); }
public ActionResult Edit(Entity.CusCategory entity) { var isAdd = entity.ID == 0 ? true : false; LoadCategorySelect(); BLL.BaseBLL <Entity.CusCategory> bll = new BLL.BaseBLL <Entity.CusCategory>(); //数据验证 if (!isAdd) { //如果要编辑的用户不存在 if (!bll.Exists(p => p.ID == entity.ID)) { return(PromptView("/admin/CusCategory", "404", "Not Found", "信息不存在或已被删除", 5)); } } if (ModelState.IsValid) { //添加 if (entity.ID == 0) { BLL.BLLCusCategory.Add(entity); } else //修改 { BLL.BLLCusCategory.Modify(entity); } return(PromptView("/admin/CusCategory", "OK", "Success", "操作成功", 5)); } else { return(View(entity)); } }
protected override void Seed(Universal.DataCore.EFDBContext context) { var role_list = new List <Entity.SysRole>() { new Entity.SysRole() { AddTime = DateTime.Now, RoleName = "管理员", RoleDesc = "管理员组", IsAdmin = true }, new Entity.SysRole() { AddTime = DateTime.Now, RoleName = "编辑用户", RoleDesc = "编辑用户组", IsAdmin = false } }; role_list.ForEach(p => context.SysRoles.AddOrUpdate(x => x.RoleName, p)); context.SaveChanges(); var role_root = context.SysRoles.Where(p => p.RoleName == "管理员").FirstOrDefault(); string pwd = SecureHelper.MD5("admin"); var user_root = new Entity.SysUser() { LastLoginTime = DateTime.Now, RegTime = DateTime.Now, NickName = "超级管理员", Password = pwd, Status = true, SysRole = role_root, UserName = "******", Gender = Entity.UserGender.男, Avatar = "" }; context.SysUsers.AddOrUpdate(p => p.UserName, user_root); var category_a = new Entity.CusCategory(); category_a.PID = null; category_a.Title = "国内"; context.CusCategorys.Add(category_a); var category_b = new Entity.CusCategory(); category_b.PID = null; category_b.Title = "世界"; context.CusCategorys.Add(category_b); var category_1 = new Entity.CusCategory(); category_1.PCategory = category_a; category_1.Title = "社会"; category_1.Depth = 2; context.CusCategorys.Add(category_1); var category_2 = new Entity.CusCategory(); category_2.PCategory = category_a; category_2.Title = "经济"; category_2.Depth = 2; context.CusCategorys.Add(category_2); var category_3 = new Entity.CusCategory(); category_3.PCategory = category_a; category_3.Title = "文化"; category_3.Depth = 2; context.CusCategorys.Add(category_3); var category_4 = new Entity.CusCategory(); category_4.PCategory = category_b; category_4.Title = "格局"; category_4.Depth = 2; context.CusCategorys.Add(category_4); var category_5 = new Entity.CusCategory(); category_5.PCategory = category_b; category_5.Title = "要闻"; category_5.Depth = 2; context.CusCategorys.Add(category_5); var category_6 = new Entity.CusCategory(); category_6.PCategory = category_b; category_6.Title = "趋势"; category_6.Depth = 2; context.CusCategorys.Add(category_6); context.SaveChanges(); }