//Save Data private void SaveData() { UserGroup userGroup = new UserGroup(); bool flag = true; try { userGroup.ParentId = UserGroup.Root.GroupId; userGroup.Name = txtName.Text.Trim(); userGroup.Description = txtDescription.Text.Trim(); userGroup.GroupType = (UserGroupType)Enum.Parse(typeof(UserGroupType),rblGroupType.SelectedValue); userGroup.GroupLevel = (short)(UserGroup.Root.GroupLevel + 1); userGroup.ModifyBy = SecuritySession.CurrentUser.UserId; userGroup.ModifyTime = DateTime.Now; using (_session = new Session()) { if (IsAddNew()) { userGroup.CreateTime = userGroup.ModifyTime; userGroup.CreateBy = SecuritySession.CurrentUser.UserId; flag = userGroup.Create(_session); } else { userGroup.GroupId = int.Parse(this.txtGroupId.Value); flag = userGroup.Update(_session, "ParentId", "Name", "Description", "GroupType", "GroupLevel","ModifyBy","ModifyTime"); } } this.txtGroupId.Value = userGroup.GroupId.ToString(); if (flag) WebUtil.ShowMsg(this, "操作成功", "提示"); else WebUtil.ShowMsg(this, "操作失败", "提示"); } catch(UnauthorizedException ex) { WebUtil.ShowMsg(this,ex.Message,"警告"); } catch(ApplicationException ex) { WebUtil.ShowMsg(this,ex.Message,"提示"); } catch(Exception ex) { logger.Info("保存UserGroup", ex); WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员"); } }
private static SimpleJson SaveUserGroup() { string opt = WebUtil.Param("opt"); UserGroup group = new UserGroup(); group.GroupId = WebUtil.ParamInt("id", 0); group.ParentId = WebUtil.ParamInt("parent", 0); group.Name = WebUtil.Param("name"); group.Description = WebUtil.Param("desc"); group.GroupType = (UserGroupType)Enum.Parse(typeof(UserGroupType), WebUtil.Param("type")); group.ModifyBy = SecuritySession.CurrentUser.UserId; group.ModifyTime = DateTime.Now; using (Session session = new Session()) { AuthorizationRepository repository = new AuthorizationRepository(session); switch (opt) { case "create": if (group.ParentId == UserGroup.Root.GroupId) group.GroupLevel = (short)(UserGroup.Root.GroupLevel + 1); else group.GroupLevel = (short)(UserGroup.Retrieve(session, group.ParentId).GroupLevel + 1); group.CreateBy = group.ModifyBy; group.CreateTime = group.ModifyTime; repository.CreateUserGroup(group); break; case "update": if (group.IsRoot) return UserGroup.Root.ToJSON(); group.Update(session, "Name", "Description", "GroupType"); break; } } return group.ToJSON(); }