public ActionResult DeleteMulti(string Id) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string[] arrId = Id.Split(new char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries); int counter = 0; foreach (var item in arrId) { int tid = Convert.ToInt32(item); Tapp_Menu model = ctx.Tapp_Menu.Include(c => c.Tapp_Button).Include(c => c.Tapp_Role_Right).FirstOrDefault(c => c.Id == tid); if (model != null) { int parentId = model.Id; if (model.Tapp_Button.Count > 0 || model.Tapp_Role_Right.Count > 0 || ctx.Tapp_Menu.Count(c => c.ParentId == parentId) > 0) { return(Content(this.GetJSON(new { Result = false, Msg = "此菜单已被引用,不能删除", id = counter }), this.JsonContentType())); } ctx.Tapp_Menu.Remove(model); counter++; } } if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Id = counter }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", id = counter }), this.JsonContentType())); }
public ActionResult Add(Tapp_Menu dto) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); ctx.Tapp_Menu.Add(dto); if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = dto }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); }
/// <summary> /// 获取权限按钮 /// </summary> /// <param name="userId"></param> /// <param name="menuCode"></param> /// <returns></returns> public List <Tapp_Button> LoadButton(int userId, string menuCode) { HKSJRecruitmentContext ctx = HttpContext.Current.GetDbContext <HKSJRecruitmentContext>(); Tapp_Menu menu = ctx.Tapp_Menu.FirstOrDefault(c => c.MenuCode == menuCode); if (menu != null) { return(LoadButton(userId, menu.Id)); } return(null); }
/// <summary> /// 获取权限按钮 /// </summary> /// <param name="userId"></param> /// <param name="controller"></param> /// <param name="action"></param> /// <returns></returns> public List <Tapp_Button> LoadButton(int userId, string controller, string action) { string url = "/" + controller + "/" + action; HKSJRecruitmentContext ctx = HttpContext.Current.GetDbContext <HKSJRecruitmentContext>(); Tapp_Menu menu = ctx.Tapp_Menu.FirstOrDefault(c => c.MenuUrl == url); if (menu != null) { return(LoadButton(userId, menu.Id)); } return(null); }
public ActionResult Detail(int Id) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Tapp_Menu dto = ctx.Tapp_Menu.FirstOrDefault(c => c.Id == Id); if (dto != null) { return(Content(this.GetJSON(new { Result = true, Dto = dto }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "未找到数据" }), this.JsonContentType())); } }
public ActionResult Edit(Tapp_Menu dto) { if (dto.Id > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); ctx.Entry <Tapp_Menu>(dto).State = System.Data.Entity.EntityState.Modified; //Tapp_Menu model = ctx.Tapp_Menu.Find(dto.Id); //model.MenuText = dto.MenuText; //model.MenuCode = dto.MenuCode; //model.MenuClass = dto.MenuClass; //model.MenuIcon = dto.MenuIcon; //model.MenuUrl = dto.MenuUrl; //model.SeqNo = dto.SeqNo; if (ctx.SaveChanges() >= 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功", Dto = dto }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败", Dto = dto }), this.JsonContentType())); } else { return(Content(this.GetJSON(new { Result = false, Msg = "失败,未找到要修改的数据", Dto = dto }), this.JsonContentType())); } }