public ActionResult Create(GroupViewModel model) { ServiceResult result = new ServiceResult(); if (ModelState.IsValid) { try { GroupService.Create(model); result.Message = "添加群组成功!"; LogHelper.WriteLog("添加群组成功"); } catch (Exception ex) { result.Message = Utilities.GetInnerMostException(ex); result.AddServiceError(result.Message); LogHelper.WriteLog("添加群组错误", ex); } } else { result.Message = "请检查表单是否填写完整!"; result.AddServiceError("请检查表单是否填写完整!"); } return Json(result); }
public Group Create(GroupViewModel model) { var entity = new Group(); entity.Name = model.Name; entity.Description = model.Description; if (!string.IsNullOrEmpty(model.RoleID)) { var RoleArray = Utilities.GetIdList(model.RoleID); var RoleList = RoleService.GetALL().Where(x => RoleArray.Contains(x.ID)); entity.Role.AddRange(RoleList); } db.Add<Group>(entity); db.Commit(); return entity; }
public Group Update(GroupViewModel model) { var entity = Find(model.ID); db.Attach<Group>(entity); entity.Name = model.Name; entity.Description = model.Description; var RoleArray = new List<int>(); if (string.IsNullOrEmpty(model.RoleID)) { entity.Role = new List<CommonP.Models.Role>(); } else { RoleArray = Utilities.GetIdList(model.RoleID); var RoletList = RoleService.GetALL().Where(x => RoleArray.Contains(x.ID)); var currentRoleArray = entity.Role.Select(x => x.ID).ToList(); foreach (CommonP.Models.Role ac in RoleService.GetALL()) { if (RoleArray.Contains(ac.ID)) { if (!currentRoleArray.Contains(ac.ID)) { entity.Role.Add(ac); } } else { if (currentRoleArray.Contains(ac.ID)) { entity.Role.Remove(ac); } } } } db.Commit(); return entity; }
public ActionResult Create() { var model = new GroupViewModel(); ViewBag.RoleID_LoadUrl = Url.Action("GetRoleCombox", "AjaxService"); return PartialView(model); }
public ActionResult Edit(int ID) { var entity = GroupService.GetALL() .Include(x => x.Role).Single(x => x.ID == ID); string RoleID = string.Join(",", entity.Role.Select(x => x.ID.ToString())); var model = new GroupViewModel() { ID = entity.ID, Description = entity.Description, Name = entity.Name, RoleID = RoleID }; ViewBag.RoleID_LoadUrl = Url.Action("GetRoleCombox", "AjaxService", new { RoleID = RoleID }); return PartialView(model); }