public ActionResult Add(Tapp_Button dto) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); ctx.Tapp_Button.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())); }
public ActionResult RightEdit(int roleid, string butIds) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); string[] arrButIds = butIds.Split(new char[] { ',', '-' }, StringSplitOptions.RemoveEmptyEntries); string[] arrDbIds = ctx.Tapp_Role_Right.Where(c => c.RoleId == roleid && c.ButtonId > 0).Select(c => c.ButtonId.ToString()).ToArray(); foreach (var item in arrDbIds.Except(arrButIds)) { //删除 int buttonId = Convert.ToInt32(item); Tapp_Role_Right right = ctx.Tapp_Role_Right.FirstOrDefault(c => c.RoleId == roleid && c.ButtonId == buttonId); if (right != null) { ctx.Tapp_Role_Right.Remove(right); } } foreach (var item in arrButIds.Except(arrDbIds)) { //新增 int buttonId = Convert.ToInt32(item); Tapp_Button button = ctx.Tapp_Button.FirstOrDefault(c => c.Id == buttonId); if (button != null) { ctx.Tapp_Role_Right.Add(new Tapp_Role_Right { RoleId = roleid, MenuId = button.MenuId, ButtonId = button.Id }); } } int ret = ctx.SaveChanges(); //检查菜单权限 List <int> menuIds = ctx.Tapp_Role_Right.Where(c => c.RoleId == roleid && c.ButtonId > 0).Select(c => c.MenuId).Distinct().ToList(); List <int> menuIds2 = ctx.Tapp_Role_Right.Where(c => c.RoleId == roleid && c.ButtonId == 0).Select(c => c.MenuId).Distinct().ToList(); foreach (var item in menuIds2.Except(menuIds)) { //删除菜单权限 Tapp_Role_Right right = ctx.Tapp_Role_Right.FirstOrDefault(c => c.RoleId == roleid && c.MenuId == item && c.ButtonId == 0); ctx.Tapp_Role_Right.Remove(right); } foreach (var item in menuIds.Except(menuIds2)) { //新增菜单权限 ctx.Tapp_Role_Right.Add(new Tapp_Role_Right { RoleId = roleid, MenuId = item, ButtonId = 0 }); } int ret2 = ctx.SaveChanges(); if (ret > 0 || ret2 > 0) { return(Content(this.GetJSON(new { Result = true, Msg = "成功" }), this.JsonContentType())); } return(Content(this.GetJSON(new { Result = false, Msg = "失败" }), this.JsonContentType())); }
public ActionResult Detail(int Id) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); Tapp_Button dto = ctx.Tapp_Button.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_Button dto) { if (dto.Id > 0) { HKSJRecruitmentContext ctx = HttpContext.GetDbContext <HKSJRecruitmentContext>(); ctx.Entry <Tapp_Button>(dto).State = System.Data.Entity.EntityState.Modified; 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())); } }
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_Button model = ctx.Tapp_Button.FirstOrDefault(c => c.Id == tid); if (model != null) { ctx.Tapp_Button.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())); }