예제 #1
0
        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 });
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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 }));
        }
예제 #5
0
 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);
     }
 }
예제 #6
0
        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();
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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.");
            }
        }
예제 #9
0
        internal static Role CreateRoleForTest(string name, BlobShareDataStoreEntities context)
        {
            Role role = new Role()
            {
                RoleName = name,
                Description = name
            };

            context.Roles.AddObject(role);
            context.SaveChanges();

            return role;
        }
예제 #10
0
 public void RemoveUserFromRole(Role role, User user)
 {
     user.Roles.Remove(role);
 }
예제 #11
0
 public void UpdateRole(Role role)
 {
     this.UpdatedRole = role;
 }
예제 #12
0
 /// <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;
 }
예제 #13
0
 public void RemoveUserFromRole(Role role, User user)
 {
     role.Users.Remove(user);
     this.context.SaveChanges();
 }
예제 #14
0
 public void AddUserToRole(Role role, User user)
 {
     role.Users.Add(user);
     this.context.SaveChanges();
 }
예제 #15
0
 public void CreateRole(Role role)
 {
     role.RoleId = Guid.NewGuid();
     this.Roles.Add(role);
     this.NewRole = role;
 }
예제 #16
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Roles EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRoles(Role role)
 {
     base.AddObject("Roles", role);
 }
예제 #17
0
 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);
 }
예제 #18
0
        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;
        }
예제 #19
0
 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);
     }
 }
예제 #20
0
 public void AddUserToRole(Role role, User user)
 {
     user.Roles.Add(role);
 }