public void IsValid() { var item = new RoleDto() { Name = Guid.NewGuid().ToString(), }; Assert.IsTrue(item.IsValid()); }
public void IsInvalid() { var item = new RoleDto() { Name = string.Empty, }; Assert.IsFalse(item.IsValid()); }
/// <summary> /// Creates a new role in the repository. /// </summary> /// <param name="role">The role.</param> /// <returns></returns> public long Create(RoleDto role) { return new Creator(this.Session).Create(role); }
/// <summary> /// Determines whether the specified role can be removed. /// </summary> /// <param name="role">The role.</param> /// <returns> /// <c>true</c> if this the specified role can be removed; otherwise, <c>false</c>. /// </returns> public bool CanRemove(RoleDto role) { return (from u in this.Session.Query<User>() where u.AssignedRole.Id == role.Id select u).Count() == 0; }
/// <summary> /// Updates the role for the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="role">The role dto.</param> public void UpdateRole(LightUserDto user, RoleDto role) { var userEntity = this.Session.Get<User>(user.Id); var roleEntity = this.Session.Get<Role>(role.Id); userEntity.AssignedRole = roleEntity; this.Session.Update(userEntity); }
/// <summary> /// Updates the specified role. /// </summary> /// <param name="role">The role.</param> public void Update(RoleDto role) { new Updator(this.Session).Update(role); }
/// <summary> /// Removes the role with the specified id. /// </summary> /// <param name="role">The role to remove.</param> public void Remove(RoleDto item) { Assert.IsNotNull(item, "item"); new Remover(this.Session).Remove<Role, RoleDto>(item, e => e.Tasks.Clear()); }
/// <summary> /// Gets the tasks that are not yet binded to the specified role. /// If the specified role is null, it'll return all the tasks stored in the /// database /// </summary> /// <param name="role">The role.</param> /// <returns>A list of tasks</returns> public TaskDto[] GetAvailableTasks(RoleDto role) { if (role == null) return new TaskDto[] { }; var tasks = Mapper.Map<IEnumerable<TaskDto>, IList<Task>>(role.Tasks); var entities = (from t in this.Session.Query<Task>() select t).ToList(); var result = new List<Task>(); foreach (var item in entities) { if (!tasks.Contains(item, new TaskEqualityComparerOnName())) { result.Add(item); } } return Mapper.Map<IEnumerable<Task>, TaskDto[]>(result); }
private static RoleDto BuildRole(string name, string description, params TaskDto[] tasks) { var role = new RoleDto() { Name = name, Description = description, }; foreach (var task in tasks) { role.Tasks.Add(task); } return role; }
/// <summary> /// Creates a new role in the repository. /// </summary> /// <param name="item">The role.</param> /// <returns></returns> public long Create(RoleDto item) { var entity = Mapper.Map<RoleDto, Role>(item); entity = this.Session.Merge(entity); this.Session.Save(entity); this.Session.Flush(); Mapper.Map<Role, RoleDto>(entity, item); item.Id = entity.Id; return entity.Id; }
private bool CanRemoveRole(RoleDto roleDto) { return component.CanRemove(roleDto); }