public void ConvertTo_WebProfileToUserProfile_ConvertedObjectHasAccurateData(int expectedId, string expectedFirstName, string expectedSurname, int expectedUserAccountId) { // Arrange DateTimeOffset expectedDate = DateTimeOffset.UtcNow; WebUserProfileModel webUserProfileModel = new WebUserProfileModel(); webUserProfileModel.Id = expectedId; webUserProfileModel.FirstName = expectedFirstName; webUserProfileModel.Surname = expectedSurname; webUserProfileModel.DateOfBirth = expectedDate; webUserProfileModel.UserAccountId = expectedUserAccountId; UserProfileModel userProfileModel = new UserProfileModel(); // Act var convertedUserProfileModel = ModelConverterService.ConvertTo(webUserProfileModel, userProfileModel); // Assert Assert.IsTrue ( convertedUserProfileModel.Id == expectedId && convertedUserProfileModel.FirstName == expectedFirstName && convertedUserProfileModel.Surname == expectedSurname && convertedUserProfileModel.DateOfBirth == expectedDate && convertedUserProfileModel.UserAccountId == expectedUserAccountId ); }
public void ConvertTo_WebAccountToUserAccount_ConvertedObjectHasAccurateData(int expectedId, string expectedUsername, string expectedEmailAddress, AccountType expectedAccountType, AccountStatus expectedAccountStatus) { // Arrange DateTimeOffset expectedDate = DateTimeOffset.UtcNow; WebUserAccountModel webUserAccountModel = new WebUserAccountModel(); webUserAccountModel.Id = expectedId; webUserAccountModel.Username = expectedUsername; webUserAccountModel.EmailAddress = expectedEmailAddress; webUserAccountModel.AccountType = expectedAccountType.ToString(); webUserAccountModel.AccountStatus = expectedAccountStatus.ToString(); webUserAccountModel.CreationDate = expectedDate; webUserAccountModel.UpdationDate = expectedDate; UserAccountModel userAccountModel = new UserAccountModel(); // Act var convertedUserAccountModel = ModelConverterService.ConvertTo(webUserAccountModel, userAccountModel); // Assert Assert.IsTrue ( convertedUserAccountModel.Id == expectedId && convertedUserAccountModel.Username == expectedUsername && convertedUserAccountModel.Password == null && convertedUserAccountModel.Salt == null && convertedUserAccountModel.EmailAddress == expectedEmailAddress && convertedUserAccountModel.AccountType == expectedAccountType.ToString() && convertedUserAccountModel.AccountStatus == expectedAccountStatus.ToString() && convertedUserAccountModel.CreationDate == expectedDate && convertedUserAccountModel.UpdationDate == expectedDate ); }
public async Task <int> UpdateListing(DALListingModel dalListingModel) { var businessListing = ModelConverterService.ConvertTo(new BusinessListingModel(), dalListingModel); int returnValue = await _listingRepository.UpdateListing(businessListing); return(returnValue); }
public async Task <WebUserAccountModel> GetUserAccountByEmail(string emailAddress) { try { var userAccountModel = await _userAccountRepository.GetAccountByEmail(emailAddress); if (userAccountModel == null) { return(null); } else { var webUserAccountModel = ModelConverterService.ConvertTo(userAccountModel, new WebUserAccountModel()); return(webUserAccountModel); } } catch (SqlCustomException e) { throw new SqlCustomException(e.Message, e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException(e.Message, e.InnerException); } }
//tracker..everytime someone visits a page i created this to track the info for the table public async Task <int> CreateLoginTracked(BusinessLoginTrackerModel businessLoginTrackerModel) { var loginTrackerModel = ModelConverterService.ConvertTo(businessLoginTrackerModel, new DALLoginTrackerModel()); var login = await _loginTrackerRepo.CreateLoginTracker(loginTrackerModel); return(login); }
public async Task <ScopeModel> GetScope(int id) { try { var dataScope = await _scopeRepository.GetScopeById(id); var scope = ModelConverterService.ConvertTo(dataScope, new BusinessModels.UserAccessControl.ScopeModel()); scope.Claims = new List <BusinessModels.UserAccessControl.ClaimModel>(); var scopeClaims = await _scopeClaimRepository.GetAllScopeClaims(); foreach (var dataScopeClaimModel in scopeClaims) { if (scope.Id == dataScopeClaimModel.ScopeId) { var dataClaimModel = await _claimRepository.GetClaimById(dataScopeClaimModel.ClaimId); var claimModel = ModelConverterService.ConvertTo(dataClaimModel, new BusinessModels.UserAccessControl.ClaimModel()); scope.Claims.Add(claimModel); } } return(scope); } catch (SqlCustomException e) { throw new SqlCustomException("Scope Not Found.", e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException("Scope was Null.", e.InnerException); } }
//tracker..everytime someone visits a page i created this to track the info for the table public async Task <int> CreatePageVisitTracked(BusinessPageVisitedTrackerModel businessPageVisitedTrackerModel) { var PageTrackerModel = ModelConverterService.ConvertTo(businessPageVisitedTrackerModel, new DALPageVisitTrackerModel()); var page = await _pageVisitTrackerRepo.CreatePageVisitTracker(PageTrackerModel); return(page); }
public async Task <WebUserProfileModel> GetUserProfileByAccountId(int accountId) { try { var userProfileModel = await _userProfileRepository.GetUserProfileByAccountId(accountId); if (userProfileModel == null) { return(null); } else { var webUserProfileModel = ModelConverterService.ConvertTo(userProfileModel, new WebUserProfileModel()); return(webUserProfileModel); } } catch (SqlCustomException e) { throw new SqlCustomException(e.Message, e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException(e.Message, e.InnerException); } }
public async Task <Result <ClaimsPrincipal> > GetUserClaimsPrincipal(int id, string role) { // Get all of a users UserScopeClaim for a specific role var userScopeClaims = await _userScopeClaimRepository.GetAllUserScopeClaimsByAccountIdAndRole(id, role); // Get all scopes from that list of UserScopeClaims var userScopes = new List <UserScopeModel>(); var userClaims = new List <UserClaimModel>(); foreach (var userScopeClaim in userScopeClaims) { var userScope = await _userScopeRepository.GetUserScopeByScopeId(userScopeClaim.UserScopeId); var userClaim = await _userClaimRepository.GetUserClaimByUserClaimId(userScopeClaim.UserClaimId); var foundDuplicateScope = false; foreach (var userScopeEntry in userScopes) { if (userScopeEntry.Id == userScopeClaim.UserScopeId) { foundDuplicateScope = true; break; } } if (!foundDuplicateScope) { userScopes.Add(ModelConverterService.ConvertTo(userScope, new UserScopeModel())); } var foundDuplicateClaim = false; foreach (var userClaimEntry in userClaims) { if (userClaimEntry.Id == userScopeClaim.UserClaimId) { foundDuplicateClaim = true; break; } } if (!foundDuplicateClaim) { userClaims.Add(ModelConverterService.ConvertTo(userClaim, new UserClaimModel())); } } var claimsPrincipal = new ClaimsPrincipal() { UserAccountId = id, Role = role, Scopes = userScopes, Claims = userClaims }; return(Result <ClaimsPrincipal> .Success(claimsPrincipal)); }
public async Task <int> CreateUserProfile(WebUserProfileModel webUserProfileModel) { try { var userProfileModel = ModelConverterService.ConvertTo(webUserProfileModel, new UserProfileModel()); return(await _userProfileRepository.CreateUserProfile(userProfileModel)); } catch (SqlCustomException e) { throw new SqlCustomException(e.Message, e.InnerException); } }
public async Task <List <BusinessTeamModel> > GetAllTeamModelListing() { var dalListing = await _traditionalListingSearchRepository.GetAllTeamListings(); List <BusinessTeamModel> businessListings = new List <BusinessTeamModel>(); foreach (var dalListingModel in dalListing) { var businessListing = ModelConverterService.ConvertTo(dalListingModel, new BusinessTeamModel()); businessListings.Add(businessListing); } return(businessListings); }
public async Task <int> CreateClaim(ClaimModel claimModel) { try { var dataClaim = ModelConverterService.ConvertTo(claimModel, new Models.User_Access_Control.ClaimModel()); var claimId = await _claimRepository.CreateClaim(dataClaim); return(claimId); } catch (SqlCustomException e) { throw new SqlCustomException("Claim could not be created.", e.InnerException); } }
public async Task <int> CreateAccount(WebUserAccountModel webUserAccountModel) { try { var userAccountModel = ModelConverterService.ConvertTo(webUserAccountModel, new UserAccountModel()); var userAccountId = await _userAccountRepository.CreateAccount(userAccountModel); return(userAccountId); } catch (SqlCustomException e) { throw new SqlCustomException(e.Message, e.InnerException); } }
public async Task <int> RegisterResource(BusinessModels.UserAccessControl.ResourceModel resourceModel) { try { var dataResource = ModelConverterService.ConvertTo(resourceModel, new Models.User_Access_Control.ResourceModel()); var resourceId = await _resourceRepository.CreateResource(dataResource); return(resourceId); } catch (SqlCustomException e) { throw new SqlCustomException("Resource could not be created.", e.InnerException); } }
public List <UserClaimModel> ExtractClaims(string token) { var decodedToken = DecodeToken(token); decodedToken.Claims.ToList().ForEach(a => { Console.WriteLine(a.Type + "-" + a.Value); }); List <UserClaimModel> userClaims = new List <UserClaimModel>(); foreach (var claim in decodedToken.Claims) { var userClaim = ModelConverterService.ConvertTo(claim, new UserClaimModel()); userClaims.Add(userClaim); } ; return(userClaims); }
public async Task <ClaimModel> GetClaim(int id) { try { var dataClaim = await _claimRepository.GetClaimById(id); var claim = ModelConverterService.ConvertTo(dataClaim, new BusinessModels.UserAccessControl.ClaimModel()); return(claim); } catch (SqlCustomException e) { throw new SqlCustomException("Claim Not Found.", e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException("Claim was Null.", e.InnerException); } }
public async Task <WebUserAccountModel> GetUserAccount(int id) { try { var userAccountModel = await _userAccountRepository.GetAccountById(id); var webUserAccountModel = ModelConverterService.ConvertTo(userAccountModel, new WebUserAccountModel()); return(webUserAccountModel); } catch (SqlCustomException e) { throw new SqlCustomException(e.Message, e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException(e.Message, e.InnerException); } }
public async Task <bool> UpdateClaim(ClaimModel claimModel) { try { var dataClaim = ModelConverterService.ConvertTo(claimModel, new Models.User_Access_Control.ClaimModel()); var changesMade = await _claimRepository.UpdateClaim(dataClaim); if (changesMade == 0) { return(false); } return(true); } catch (SqlCustomException e) { throw new SqlCustomException("Claim could not be updated.", e.InnerException); } }
public async Task <bool> UpdateScope(ScopeModel scopeModel) { try { var dataScope = ModelConverterService.ConvertTo(scopeModel, new Models.User_Access_Control.ScopeModel()); var changesMade = await _scopeRepository.UpdateScope(dataScope); if (changesMade == 0) { return(false); } return(true); } catch (SqlCustomException e) { throw new SqlCustomException("Scope could not be updated.", e.InnerException); } }
public async Task <BusinessModels.UserAccessControl.ResourceModel> GetResource(int id) { try { var dataResource = await _resourceRepository.GetResourceById(id); var resource = ModelConverterService.ConvertTo(dataResource, new BusinessModels.UserAccessControl.ResourceModel()); return(resource); } catch (SqlCustomException e) { throw new SqlCustomException("Resource Not Found.", e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException("Resource was Null.", e.InnerException); } }
public async Task <List <ScopeModel> > GetAllScopes() { try { var scopes = await _scopeRepository.GetAllScopes(); List <BusinessModels.UserAccessControl.ScopeModel> scopeList = new List <BusinessModels.UserAccessControl.ScopeModel>(); foreach (var dataScopeModel in scopes) { var scopeModel = ModelConverterService.ConvertTo(dataScopeModel, new BusinessModels.UserAccessControl.ScopeModel()); scopeModel.Claims = new List <BusinessModels.UserAccessControl.ClaimModel>(); var scopeClaims = await _scopeClaimRepository.GetAllScopeClaims(); foreach (var dataScopeClaimModel in scopeClaims) { if (scopeModel.Id == dataScopeClaimModel.ScopeId) { var dataClaimModel = await _claimRepository.GetClaimById(dataScopeClaimModel.ClaimId); var claimModel = ModelConverterService.ConvertTo(dataClaimModel, new BusinessModels.UserAccessControl.ClaimModel()); scopeModel.Claims.Add(claimModel); } } scopeList.Add(scopeModel); } return(scopeList); } catch (SqlCustomException e) { throw new SqlCustomException("No Scopes Found.", e.InnerException); } }
public async Task <List <ClaimModel> > GetAllClaims() { try { var claims = await _claimRepository.GetAllClaims(); List <BusinessModels.UserAccessControl.ClaimModel> claimList = new List <BusinessModels.UserAccessControl.ClaimModel>(); foreach (var claim in claims) { claimList.Add(ModelConverterService.ConvertTo(claim, new BusinessModels.UserAccessControl.ClaimModel())); } return(claimList); } catch (SqlCustomException e) { throw new SqlCustomException("No Claims Found.", e.InnerException); } }
public async Task <Result <bool> > AddUserClaim(UserClaimModel userClaimModel, string scope, string description) { // check to see if the desired scope exists var dalUserClaims = await _userClaimRepository.GetAllUserClaimsByUserAccountId(userClaimModel.UserAccountId); var claimMatch = (dalUserClaims.Where(x => x.Type == userClaimModel.Type).FirstOrDefault()); if (claimMatch != null) { return(Result <bool> .Failure(ErrorMessage.UserAlreadyContainsClaim)); } var dalScopes = (await _scopeRepository.GetAllScopes()).ToList(); var scopeMatch = dalScopes.Where(x => x.Type == scope).FirstOrDefault(); int scopeId = -1; if (scopeMatch == null) { scopeId = await _scopeRepository.CreateScope(new ScopeModel() { Type = scope, Description = description, IsDefault = false }); } else { scopeId = scopeMatch.Id; } var claimId = await _userClaimRepository.CreateUserClaim(ModelConverterService.ConvertTo(userClaimModel, new DALUserClaimModel())); await _scopeClaimRepository.CreateScopeClaim(new ScopeClaimModel() { ScopeId = scopeId, ClaimId = claimId }); return(Result <bool> .Success(true)); }
public void ConvertTo_WebToUser_ConversionSuccessful(int expectedId, string expectedUsername, string expectedEmailAddress, AccountType expectedAccountType, AccountStatus expectedAccountStatus) { // Arrange WebUserAccountModel webUserAccountModel = new WebUserAccountModel(); webUserAccountModel.Id = expectedId; webUserAccountModel.Username = expectedUsername; webUserAccountModel.EmailAddress = expectedEmailAddress; webUserAccountModel.AccountType = expectedAccountType.ToString(); webUserAccountModel.AccountStatus = expectedAccountStatus.ToString(); webUserAccountModel.CreationDate = DateTimeOffset.UtcNow; webUserAccountModel.UpdationDate = DateTimeOffset.UtcNow; UserAccountModel userAccountModel = new UserAccountModel(); // Act var convertedUserAccountModel = ModelConverterService.ConvertTo <WebUserAccountModel, UserAccountModel>(webUserAccountModel, userAccountModel); // Assert Assert.IsTrue(convertedUserAccountModel.GetType().Equals(typeof(UserAccountModel))); }
public async Task <int> CreateScope(ScopeModel scopeModel) { try { var dataScope = ModelConverterService.ConvertTo(scopeModel, new Models.User_Access_Control.ScopeModel()); var scopeId = await _scopeRepository.CreateScope(dataScope); foreach (var claim in scopeModel.Claims) { await _scopeClaimRepository.CreateScopeClaim(new Models.User_Access_Control.ScopeClaimModel() { ScopeId = scopeId, ClaimId = claim.Id }); } return(scopeId); } catch (SqlCustomException e) { throw new SqlCustomException(e.InnerException.Message, e.InnerException); } }
public async Task <List <WebUserProfileModel> > GetAllUsers() { try { var userProfiles = await _userProfileRepository.GetAllUserProfiles(); List <WebUserProfileModel> webUserProfiles = new List <WebUserProfileModel>(); foreach (var userProfileModel in userProfiles) { var webUserProfileModel = ModelConverterService.ConvertTo(userProfileModel, new WebUserProfileModel()); webUserProfiles.Add(webUserProfileModel); } return(webUserProfiles); } catch (SqlCustomException e) { throw new SqlCustomException(e.Message, e.InnerException); } catch (NullReferenceException e) { throw new NullReferenceException(e.Message, e.InnerException); } }
public async Task <List <BusinessModels.UserAccessControl.ResourceModel> > GetAllResources() { try { var resources = await _resourceRepository.GetAllResources(); List <BusinessModels.UserAccessControl.ResourceModel> resourceList = new List <BusinessModels.UserAccessControl.ResourceModel>(); foreach (var dataResourceModel in resources) { var resourceModel = ModelConverterService.ConvertTo(dataResourceModel, new BusinessModels.UserAccessControl.ResourceModel()); resourceList.Add(resourceModel); } return(resourceList); } catch (SqlCustomException e) { throw new SqlCustomException("No Resources Found.", e.InnerException); } }
public async Task <int> CreateListing(BusinessListingModel businessListingmodel) { if (businessListingmodel is BusinessCollaborationModel) { // Step 1: Create businessListingModel BusinessCollaborationModel newBusinessCollaborationModel = (BusinessCollaborationModel)businessListingmodel; BusinessListingModel newBusinessListingModel = new BusinessListingModel(); // Step 2: Access parent props of collaboration Model to the step 1 model newBusinessListingModel.Title = newBusinessCollaborationModel.Title; newBusinessListingModel.Details = newBusinessCollaborationModel.Details; newBusinessListingModel.City = newBusinessCollaborationModel.City; newBusinessListingModel.State = newBusinessCollaborationModel.State; newBusinessListingModel.NumberOfParticipants = newBusinessCollaborationModel.NumberOfParticipants; newBusinessListingModel.InPersonOrRemote = newBusinessCollaborationModel.InPersonOrRemote; newBusinessListingModel.UserAccountId = newBusinessCollaborationModel.UserAccountId; DALListingModel dALListingModel = new DALListingModel(); DALCollaborationModel dALCollaborationModel = new DALCollaborationModel(); // Step 3 : Convert both originalBusinessListingModel and step 1 created model to DALListingModel and DALCollaboration model var dalListingModel = ModelConverterService.ConvertTo(newBusinessListingModel, dALListingModel); var dalCollaborationModel = ModelConverterService.ConvertTo(newBusinessCollaborationModel, dALCollaborationModel); // Step 4 : Call ListingRepo pass in DalListing Model, call CollaborationRepo pass in CollaborationModel to both create Functions in the repo var result = await _listingRepository.CreateListing(dalListingModel); dalCollaborationModel.ListingId = result; await _collaborationRepository.CreateListing(dalCollaborationModel); //collaboration repo instead of listing repo return(result); } else if (businessListingmodel is BusinessRelationshipModel) { // Same steps as is BusinessCollaborationModel // Step 1: Create businessListingModel BusinessRelationshipModel newBusinessRelationshipModel = (BusinessRelationshipModel)businessListingmodel; BusinessListingModel newBusinessListingModel = new BusinessListingModel(); // Step 2: Access parent props of collaboration Model to the step 1 model newBusinessListingModel.Title = newBusinessRelationshipModel.Title; newBusinessListingModel.Details = newBusinessRelationshipModel.Details; newBusinessListingModel.City = newBusinessRelationshipModel.City; newBusinessListingModel.State = newBusinessRelationshipModel.State; newBusinessListingModel.NumberOfParticipants = newBusinessRelationshipModel.NumberOfParticipants; newBusinessListingModel.InPersonOrRemote = newBusinessRelationshipModel.InPersonOrRemote; newBusinessListingModel.UserAccountId = newBusinessRelationshipModel.UserAccountId; DALListingModel dALListingModel = new DALListingModel(); DALRelationshipModel dALRelationshipModel = new DALRelationshipModel(); //Step 3: Convert both originalBusinessListingModel and step 1 created model to DALListingModel and DALCollaboration model var dalListingModel = ModelConverterService.ConvertTo(newBusinessListingModel, dALListingModel); var dalRelationshipModel = ModelConverterService.ConvertTo(newBusinessRelationshipModel, dALRelationshipModel); // Step 4 : Call ListingRepo pass in DalListing Model, call CollaborationRepo pass in CollaborationModel to both create Functions in the repo var result = await _listingRepository.CreateListing(dalListingModel); dalRelationshipModel.ListingId = result; await _relationshipRepository.CreateListing(dalRelationshipModel); //collaboration repo instead of listing repo return(result); } else if (businessListingmodel is BusinessDatingModel) { // Create ListingModel, RelationshipModel, DatingModel // Same steps but instead of 2 models to be created, i need to create 3 BusinessRelationshipModel newBusinessRelationshipModel = (BusinessRelationshipModel)businessListingmodel; BusinessListingModel newBusinessListingModel = new BusinessListingModel(); BusinessDatingModel newBusinessDatingModel = (BusinessDatingModel)businessListingmodel; newBusinessListingModel.Title = newBusinessRelationshipModel.Title; newBusinessListingModel.Details = newBusinessRelationshipModel.Details; newBusinessListingModel.City = newBusinessRelationshipModel.City; newBusinessListingModel.State = newBusinessRelationshipModel.State; newBusinessListingModel.NumberOfParticipants = newBusinessRelationshipModel.NumberOfParticipants; newBusinessListingModel.InPersonOrRemote = newBusinessRelationshipModel.InPersonOrRemote; newBusinessListingModel.UserAccountId = newBusinessRelationshipModel.UserAccountId; DALListingModel dALListingModel = new DALListingModel(); DALRelationshipModel dALRelationshipModel = new DALRelationshipModel(); } else if (businessListingmodel is BusinessTeamModel) { BusinessTeamModel newBusinessTeamModel = (BusinessTeamModel)businessListingmodel; BusinessListingModel newBusinessListingModel = new BusinessListingModel(); newBusinessListingModel.Title = newBusinessTeamModel.Title; newBusinessListingModel.Details = newBusinessTeamModel.Details; newBusinessListingModel.City = newBusinessTeamModel.City; newBusinessListingModel.State = newBusinessTeamModel.State; newBusinessListingModel.NumberOfParticipants = newBusinessTeamModel.NumberOfParticipants; newBusinessListingModel.InPersonOrRemote = newBusinessTeamModel.InPersonOrRemote; newBusinessListingModel.UserAccountId = newBusinessTeamModel.UserAccountId; DALListingModel dALListingModel = new DALListingModel(); DALTeamModel dALTeamModel = new DALTeamModel(); var dalListingModel = ModelConverterService.ConvertTo(newBusinessListingModel, dALListingModel); var dalTeamModel = ModelConverterService.ConvertTo(newBusinessTeamModel, dALTeamModel); var result = await _listingRepository.CreateListing(dalListingModel); dalTeamModel.ListingId = result; await _teamModelRepository.CreateListing(dalTeamModel); //collaboration repo instead of listing repo return(result); } return(0); }
public HomeController(MusicService service, ModelConverterService converterService, LikedSongsService likedSongsService) { _service = service; _converterService = converterService; _likedSongsService = likedSongsService; }