/// <summary> /// Gets the role. /// </summary> /// <param name="roleIdDetails">The role identifier details.</param> /// <returns></returns> public async Task <CSSResponse> GetRole(RoleIdDetails roleIdDetails) { Role roleDetails; if (roleIdDetails.RoleId == 0) { roleDetails = new Role { RoleId = 0, Name = "Agent" }; } else { roleDetails = await _repository.Roles.GetRole(roleIdDetails); if (roleDetails == null) { return(new CSSResponse(HttpStatusCode.NotFound)); } } var mappedRole = _mapper.Map <RoleDTO>(roleDetails); return(new CSSResponse(mappedRole, HttpStatusCode.OK)); }
public async Task <Role> GetAllRole(RoleIdDetails roleIdDetails) { var role = FindByCondition(x => x.RoleId == roleIdDetails.RoleId) .SingleOrDefault(); return(await Task.FromResult(role)); }
/// <summary> /// Updates the role. /// </summary> /// <param name="roleIdDetails">The role identifier details.</param> /// <param name="roleDetails">The role details.</param> /// <returns></returns> public async Task <CSSResponse> UpdateRole(RoleIdDetails roleIdDetails, UpdateRoleDTO roleDetails) { Role role = await _repository.Roles.GetRole(roleIdDetails); if (role == null) { return(new CSSResponse(HttpStatusCode.NotFound)); } var roles = await _repository.Roles.GetRolesByName(new RoleNameDetails { Name = roleDetails.Name }); if (roles?.Count > 0 && roles.IndexOf(roleIdDetails.RoleId) == -1) { return(new CSSResponse($"role with Role Name '{roleDetails.Name}' already exists.", HttpStatusCode.Conflict)); } var roleDetailsPreUpdate = new Role { RoleId = role.RoleId, Name = role.Name, Description = role.Description, IsDeleted = role.IsDeleted, ModifiedDate = role.ModifiedDate }; var roleRequest = _mapper.Map(roleDetails, role); _repository.Roles.UpdateRole(roleRequest); await _repository.SaveAsync(); //_bus.SendCommand<UpdateroleCommand>( // MassTransitConstants.roleUpdateCommandRouteKey, // new // { // Id = roleRequest.Id, // Sso = roleDetailsPreUpdate.Sso, // EmployeeId = roleDetailsPreUpdate.EmployeeId, // Firstname = roleDetailsPreUpdate.Firstname, // Lastname = roleDetailsPreUpdate.Lastname, // ModifiedDate = roleRequest.ModifiedDate // }); return(new CSSResponse(HttpStatusCode.NoContent)); }
/// <summary> /// Deletes the role. /// </summary> /// <param name="roleIdDetails">The role identifier details.</param> /// <returns></returns> public async Task <CSSResponse> DeleteRole(RoleIdDetails roleIdDetails) { var role = await _repository.Roles.GetRole(roleIdDetails); if (role == null) { return(new CSSResponse(HttpStatusCode.NotFound)); } var roleDetailsPreUpdate = new Role { RoleId = role.RoleId, Name = role.Name, Description = role.Description, IsDeleted = role.IsDeleted, ModifiedDate = role.ModifiedDate }; role.IsDeleted = true; _repository.Roles.UpdateRole(role); await _repository.SaveAsync(); //_bus.SendCommand<DeleteroleCommand>( // MassTransitConstants.roleDeleteCommandRouteKey, // new // { // Sso = role.Sso, // EmployeeId = role.EmployeeId, // Firstname = role.Firstname, // Lastname = role.Lastname, // IsDeletedOldValue = roleDetailsPreUpdate.IsDeleted, // ModifiedDateOldValue = roleDetailsPreUpdate.ModifiedDate, // IsDeletedNewValue = role.IsDeleted // }); return(new CSSResponse(HttpStatusCode.NoContent)); }
/// <summary>Reverts the role.</summary> /// <param name="roleIdDetails">The role identifier details.</param> /// <param name="roleDetails">The role details.</param> /// <returns> /// <br /> /// </returns> public async Task <CSSResponse> RevertRole(RoleIdDetails roleIdDetails, UpdateRoleDTO roleDetails) { Role role = await _repository.Roles.GetAllRole(roleIdDetails); if (role == null) { return(new CSSResponse(HttpStatusCode.NotFound)); } var roles = await _repository.Roles.GetRolesByName(new RoleNameDetails { Name = roleDetails.Name }); if (roles?.Count > 0 && roles.IndexOf(roleIdDetails.RoleId) == -1) { return(new CSSResponse($"role with Role Name '{roleDetails.Name}' already exists.", HttpStatusCode.Conflict)); } var roleRequest = _mapper.Map(roleDetails, role); _repository.Roles.UpdateRole(roleRequest); await _repository.SaveAsync(); return(new CSSResponse(HttpStatusCode.NoContent)); }