public ActionResult Create(RoleEditViewModel model) { if (!this.ModelState.IsValid) { return View(model); } var role = new Role() { RoleName = model.Name, Description = model.Description }; try { this.roleService.CreateRole(role); } catch (Exception ex) { this.ModelState.AddModelError("Name", ex.Message); return View(model); } return RedirectToAction("Details", new { id = role.RoleId }); }
public void CreateRole() { using (TransactionScope ts = new TransactionScope()) { RoleService service = new RoleService(); Role role = new Role() { RoleName = "Test Role" }; service.CreateRole(role); Assert.AreNotEqual(Guid.Empty, role.RoleId); } }
public void RaiseIfDuplicateRole() { using (TransactionScope ts = new TransactionScope()) { RoleService service = new RoleService(); Role role = new Role() { RoleName = "Test Role" }; service.CreateRole(role); Role newRole = new Role() { RoleName = "Test Role" }; service.CreateRole(newRole); } }
public ActionResult GrantRolePermission(Guid id, Guid?selectedRole, int selectedExpiration) { if (selectedRole.HasValue && !selectedRole.Equals(Guid.Empty) && selectedExpiration > 0) { Microsoft.Samples.DPE.BlobShare.Data.Model.Role role = this.roleService.GetRoleById(selectedRole.Value); Blob blob = this.blobService.GetBlobById(id); DateTime expiration = this.GetExpiration(selectedExpiration); this.permissionService.GrantPermissionToRoleBlob(Privilege.Read, role, blob, expiration); } return(RedirectToAction("Permissions", new { id = id })); }
public void GetRoleByName() { using (TransactionScope ts = new TransactionScope()) { RoleService service = new RoleService(); Role role = new Role() { RoleName = "Test Role" }; service.CreateRole(role); Role newRole = service.GetRoleByName(role.RoleName); Assert.IsNotNull(newRole); Assert.AreEqual(role.RoleName, newRole.RoleName); Assert.AreEqual(role.RoleId, newRole.RoleId); } }
public void CreateRole(Role role) { var currentRole = this.context.Roles.Where(r => r.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); if (currentRole != null) { throw new InvalidOperationException("Role already exists."); } if (role.RoleId == Guid.Empty) { role.RoleId = Guid.NewGuid(); } this.context.Roles.AddObject(role); this.context.SaveChanges(); }
public void GetRoles() { using (TransactionScope ts = new TransactionScope()) { RoleService service = new RoleService(); for (int k = 1; k <= 10; k++) { Role role = new Role() { RoleName = "Test Role " + k }; service.CreateRole(role); } IQueryable<Role> roles = service.GetRoles(); Assert.IsNotNull(roles); Assert.IsTrue(roles.Count() >= 10); } }
public void UpdateRole(Role role) { var findRole = this.context.Roles.Where(r => r.RoleName.Equals(role.RoleName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); if (findRole != null) { throw new InvalidOperationException("Role already exists."); } var currentRole = this.context.Roles.Where(r => r.RoleId == role.RoleId).SingleOrDefault(); if (currentRole != null) { currentRole.RoleName = role.RoleName; this.context.SaveChanges(); } else { throw new InvalidOperationException("Role does not exist."); } }
internal static Role CreateRoleForTest(string name, BlobShareDataStoreEntities context) { Role role = new Role() { RoleName = name, Description = name }; context.Roles.AddObject(role); context.SaveChanges(); return role; }
public void RemoveUserFromRole(Role role, User user) { user.Roles.Remove(role); }
public void UpdateRole(Role role) { this.UpdatedRole = role; }
/// <summary> /// Create a new Role object. /// </summary> /// <param name="roleId">Initial value of the RoleId property.</param> /// <param name="roleName">Initial value of the RoleName property.</param> public static Role CreateRole(global::System.Guid roleId, global::System.String roleName) { Role role = new Role(); role.RoleId = roleId; role.RoleName = roleName; return role; }
public void RemoveUserFromRole(Role role, User user) { role.Users.Remove(user); this.context.SaveChanges(); }
public void AddUserToRole(Role role, User user) { role.Users.Add(user); this.context.SaveChanges(); }
public void CreateRole(Role role) { role.RoleId = Guid.NewGuid(); this.Roles.Add(role); this.NewRole = role; }
/// <summary> /// Deprecated Method for adding a new object to the Roles EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToRoles(Role role) { base.AddObject("Roles", role); }
public IEnumerable<BlobSet> GetBlobSetsByRole(Role role) { return role.Permissions.Where(p => p.BlobSet != null && p.ExpirationDateTime > DateTime.UtcNow).Select(p => p.BlobSet).Distinct().OrderBy(rs => rs.Name); }
public Permission GrantPermissionToRoleBlobSet(Privilege privilege, Role role, BlobSet set, DateTime expiration) { var permission = new Permission() { PermissionId = Guid.NewGuid(), Privilege = (int)privilege, BlobSet = set, CreationDateTime = DateTime.UtcNow, ExpirationDateTime = expiration }; permission.Roles.Add(this.context.Roles.Single(r => r.RoleId == role.RoleId)); this.context.Permissions.AddObject(permission); this.context.SaveChanges(); return permission; }
public void UpdateRole() { using (TransactionScope ts = new TransactionScope()) { RoleService service = new RoleService(); Role role = new Role() { RoleName = "Test Role" }; service.CreateRole(role); Role updatedRole = new Role() { RoleId = role.RoleId, RoleName = "New Test Role" }; service.UpdateRole(updatedRole); Role newRole = service.GetRoleById(role.RoleId); Assert.IsNotNull(newRole); Assert.AreEqual("New Test Role", newRole.RoleName); } }
public void AddUserToRole(Role role, User user) { user.Roles.Add(role); }