public IEnumerable <string> Get() { var user = new Entity.User { Id = Guid.NewGuid().ToString(), Age = 1.2, Name = "里斯", Sex = 1 }; var role = new Entity.Role() { Id = Guid.NewGuid().ToString(), Name = "角色", }; var user_role = new Entity.UserRole() { Id = Guid.NewGuid().ToString(), //Role = role, //UserCurrent = user, //UserParent = new Entity.User() //{ // Id = Guid.NewGuid().ToString(), // Age = 0.2, // Name = "里da斯", // Sex = 1 //} }; context.Set <Entity.UserRole>().Add(user_role); var i = context.SaveChanges(); return(new string[] { "value1", "value2" }); }
public void Add(RoleModel model) { if (string.IsNullOrEmpty(model.Name)) { throw new Exception("角色名称无效"); } var dbContext = ServiceProvider.GetDbcontext <IPurocumentDbcontext>(); if (string.IsNullOrEmpty(model.Code)) { throw new Exception("角色编码无效"); } if (dbContext.Role.Count(c => c.Code == model.Code) > 0) { throw new Exception("角色编码无效"); } var entity = new Entity.Role() { WechatGroupID = model.WechatGroupID, Code = model.Code, Name = model.Name }; dbContext.Add(entity); dbContext.SaveChanges(); }
/// <summary> /// Waits for a user to log in before intializing the service. /// </summary> private void WaitForLogin() { MessagingCenter.Subscribe <AppCore, Entity.Role>(this, "StartBluetooth", (sender, role) => { this.role = role; Init(); }); }
public override void CreateRole(string roleName) { var newRole = new Entity.Role() { RoleName = roleName }; RoleService.AddRole(newRole); }
public RoleModel(Entity.Role role) { this.Name = role.Name; this.Id = role.Id; this.IsForbidden = role.IsForbidden ? ForbiddenStatusEnum.Forbidden : ForbiddenStatusEnum.Normal; this.CreateTime = role.CreateTime; this.UpdateTime = role.UpdateTime; this.CreatedByUserName = role.CreateByUserName; this.Description = role.Description; }
public bool EditRole(Entity.Role role, out string errorMsg) { errorMsg = string.Empty; try { int updateCount = roleRep.UpdateOnly(role, r => r.Id == role.Id, r => new { role.Name, role.Code, role.Description }); return(true); } catch (Exception ex) { errorMsg = ex.Message; return(false); } }
public bool AddNewRole(Entity.Role role, out string errorMsg) { errorMsg = string.Empty; try { roleRep.Insert(role); return(true); } catch (Exception ex) { errorMsg = ex.Message; return(false); } }
/// <summary> /// Persists the <paramref name="role" /> to the data store. The role can be an existing one or a new one to be /// created. /// </summary> /// <param name="role">The role.</param> /// <returns>An instance of <see cref="HttpResponseMessage" />.</returns> /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the requested action is not successful.</exception> public HttpResponseMessage Post(Entity.Role role) { // POST /api/roles try { // Don't need to check security here because we'll do that in RoleController.Save. RoleController.Save(role); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(String.Format(CultureInfo.CurrentCulture, "Role '{0}' has been saved", Utils.HtmlEncode(role.Name))) }); } catch (InvalidGalleryServerRoleException ex) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent(ex.Message), ReasonPhrase = "Action Forbidden" }); } catch (GallerySecurityException ex) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent(ex.Message), ReasonPhrase = "Action Forbidden" }); } catch (Exception ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = Utils.GetExStringContent(ex), ReasonPhrase = "Server Error" }); } finally { HelperFunctions.RemoveCache(CacheItem.GalleryServerRoles); } }
[PreferredConstructorAttribute] // Preferred constructor for locator public RoleViewModel() { Model = new Entity.Role(); // Create new Role when first creating this ViewModel //AddEmployeeCommand = new RelayCommand(Add); }
public RoleViewModel(Entity.Role role) { this.Model = role; }
/// <summary> /// Gets a role entity corresponding to <paramref name="roleName" />. If the role does not exist, an instance with /// a set of default values is returned that can be used to create a new role. The instance can be serialized to JSON and /// subsequently used in the browser as a data object. A <see cref="GallerySecurityException" /> is thrown if the current /// user doesn't have permission to view the role. /// </summary> /// <param name="roleName">Name of the role.</param> /// <returns>Returns an <see cref="Entity.Role" /> instance.</returns> /// <exception cref="GallerySecurityException">Thrown when the current user does not have permission to view the role.</exception> public static Entity.Role GetRoleEntity(string roleName) { var role = Factory.LoadGalleryServerRole(roleName, true); // Throw exception if user can't view role. Note that GSP doesn't differentiate between permission to view and permission to // edit, so we use the UserCanEditRole function, even though we are just getting a role, not editing it. if (role != null && !UserCanViewRole(role)) throw new GallerySecurityException("Insufficient permission to view role."); Entity.Role r = new Entity.Role(); Entity.Permissions p = new Entity.Permissions(); if (role != null) { r.Name = role.RoleName; r.IsNew = false; r.IsOwner = (IsRoleAnAlbumOwnerRole(r.Name) || IsRoleAnAlbumOwnerTemplateRole(r.Name)); p.ViewAlbumOrMediaObject = role.AllowViewAlbumOrMediaObject; p.ViewOriginalMediaObject = role.AllowViewOriginalImage; p.AddChildAlbum = role.AllowAddChildAlbum; p.AddMediaObject = role.AllowAddMediaObject; p.EditAlbum = role.AllowEditAlbum; p.EditMediaObject = role.AllowEditMediaObject; p.DeleteAlbum = false; // This permission exists only in the context of a particular album and not as a stand-alone permission p.DeleteChildAlbum = role.AllowDeleteChildAlbum; p.DeleteMediaObject = role.AllowDeleteMediaObject; p.Synchronize = role.AllowSynchronize; p.AdministerGallery = role.AllowAdministerGallery; p.AdministerSite = role.AllowAdministerSite; p.HideWatermark = role.HideWatermark; } else { r.IsNew = true; } r.Permissions = p; IIntegerCollection rootAlbumIds = (role != null ? role.RootAlbumIds : new IntegerCollection()); Entity.TreeViewOptions tvOptions = new Entity.TreeViewOptions() { EnableCheckboxPlugin = true, RequiredSecurityPermissions = SecurityActions.AdministerSite | SecurityActions.AdministerGallery, Galleries = Factory.LoadGalleries(), RootAlbumPrefix = String.Concat(Resources.GalleryServerPro.Site_Gallery_Text, " '{GalleryDescription}': "), SelectedAlbumIds = rootAlbumIds }; Entity.TreeView tv = AlbumTreeViewBuilder.GetAlbumsAsTreeView(tvOptions); r.AlbumTreeDataJson = tv.ToJson(); r.SelectedRootAlbumIds = rootAlbumIds.ToArray(); r.Members = RoleController.GetUsersInRole(r.Name); return r; }
protected void btn_save_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(sGuid)) { //Add Guid guid = Guid.NewGuid(); Md5 md5 = new Md5(); if (txt_vPassWord1.Text.Trim() != txt_vPassWord2.Text.Trim()) { Alert.ShowInTop("2次输入的密码不一致。"); return; } Entity.UserRole userrole = new Entity.UserRole(); userrole.user.GUID = guid.ToString(); userrole.user.PassWord = md5.Md5Encrypt(txt_vPassWord1.Text.Trim()); userrole.user.CreateDate = DateTime.Now; userrole.user.CreateUser = Request.Cookies["Cookies"].Values["UserName"].ToString(); userrole.user.IsStop = bool.Parse(CheckStop.SelectedValue); userrole.user.PwdChgDate = DateTime.Now; userrole.user.RealName = txt_RealName.Text; userrole.user.UserName = txt_vUserName.Text; userrole.user.UpdateDate = DateTime.Now; userrole.user.UpdateUser = Request.Cookies["Cookies"].Values["UserName"].ToString(); List <Entity.Role> roles = new List <Entity.Role>(); foreach (string roleID in Role.SelectedValueArray) { Entity.Role role = new Entity.Role(); role.ID = int.Parse(roleID); roles.Add(role); } userrole.role = roles; //userrole.role.ID = int.Parse(drop_Role.SelectedValue.ToString()); int success = DAL.UserRole.AddUserRole(userrole); if (success == 1) { Alert.ShowInTop(" 保存成功!", MessageBoxIcon.Information); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference("self.opener.location.reload();")); //Response.Redirect("~/Basic/UserList.aspx"); } else { Alert.ShowInTop("保存失败!", MessageBoxIcon.Warning); } } else { //Update //Guid guid = Guid.NewGuid(); //Md5 md5 = new Md5(); Entity.UserRole userrole = new Entity.UserRole(); userrole.user.GUID = sGuid; userrole.user.IsStop = bool.Parse(CheckStop.SelectedValue); //userrole.user.PwdChgDate = DateTime.Now; userrole.user.RealName = txt_RealName.Text; userrole.user.UserName = txt_vUserName.Text; userrole.user.UpdateDate = DateTime.Now; userrole.user.UpdateUser = Request.Cookies["Cookies"].Values["UserName"].ToString(); Entity.UserRole userrole2 = DAL.UserRole.GetUserRoleByGUID(sGuid); if (!string.IsNullOrEmpty(userrole2.user.UserName)) { List <Entity.Role> roles = userrole2.role; string[] Roles = new string[roles.Count]; for (int i = 0; i < roles.Count; i++) { Roles[i] = roles[i].ID.ToString(); OldIDs.Add(roles[i].ID); } } List <Entity.Role> roles2 = new List <Entity.Role>(); foreach (string roleID in Role.SelectedValueArray) { Entity.Role role = new Entity.Role(); role.ID = int.Parse(roleID); NewIDs.Add(role.ID); } userrole.role = roles2; //var add = NewIDs.Except(OldIDs); //var delete = OldIDs.Except(NewIDs); //var add = NewIDs; //var delete = OldIDs; List <int> Add = ListHelper.ExceptList(NewIDs, OldIDs); List <int> Delete = ListHelper.ExceptList(OldIDs, NewIDs); //List<int> Add = new List<int>(); //List<int> Delete = new List<int>(); //foreach(string a in add) //{ // Add.Add(int.Parse(a)); //} //foreach (string b in delete) //{ // Delete.Add(int.Parse(b)); //} userrole.Add = Add; userrole.Delete = Delete; int success = DAL.UserRole.UpdateUserRole(userrole); if (success == 1) { Alert.ShowInTop(" 修改成功!", MessageBoxIcon.Information); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference("self.opener.location.reload();")); //Response.Redirect("~/Basic/UserList.aspx"); } else { Alert.ShowInTop("修改失败!", MessageBoxIcon.Warning); } } }
public static RoleModel Convert(Entity.Role arg) { return(new RoleModel(arg)); }