public async Task <IActionResult> RemoveClaim(string scope, string claim) { var editScope = await _scopeService.Find(scope); if (editScope == null) { ModelState.AddModelError("FindScope", $"Scope with the name {scope} could not be found."); return(PartialView("ScopeClaimList")); } var claimToRemove = editScope.Claims.SingleOrDefault(scopeClaim => scopeClaim.Name == claim); if (claimToRemove == default(ScopeClaim)) { ModelState.AddModelError("FindClaim", $"Claim with the name {claim} was not found in the scope {scope}"); return(PartialView("ScopeClaimList")); } editScope.Claims.Remove(claimToRemove); await _scopeService.Save(editScope); var scopeModel = new ScopeModel(editScope); return(PartialView("ScopeClaimList", scopeModel)); }
public async Task <IActionResult> EditClaim(ScopeClaimModel claimModel) { var claimScope = await _scopeService.Find(claimModel.ScopeName); if (claimScope == null) { ModelState.AddModelError("FindScope", $"Scope with the name {claimModel.ScopeName} could not be found."); return(PartialView("ScopeClaimList")); } var claimToRemove = claimScope.Claims.SingleOrDefault(scopeClaim => scopeClaim.Name == claimModel.ClaimId); if (claimToRemove == default(ScopeClaim)) { ModelState.AddModelError("FindClaim", $"Claim with the name {claimModel.ClaimId} was not found in the scope {claimModel.ScopeName}"); return(PartialView("ScopeClaimList")); } int index = claimScope.Claims.IndexOf(claimToRemove); claimScope.Claims[index] = claimModel.ScopeClaim; await _scopeService.Save(claimScope); var scopeModel = new ScopeModel(claimScope); ModelState.Clear(); PartialViewResult partialViewResult = PartialView("ScopeClaimList", scopeModel); return(partialViewResult); }
public HttpResponseMessage Put(int id, ScopeModel model) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors())); } var scope = config.Scopes.All.SingleOrDefault(x => x.ID == id); if (scope == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var query = (from a in this.config.Applications.All from s in a.Scopes where s.ID == id select a); var app = query.Single(); if (app.Scopes.Any(x => x.Name == model.Name && x.ID != id)) { ModelState.AddModelError("", "That Scope name is already in use."); return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors())); } scope.DisplayName = model.DisplayName; scope.Description = model.Description; scope.Emphasize = model.Emphasize; config.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.NoContent)); }
public async Task UpdateScope_ScopeExists_ScopeNameIsAccurate(int id, string expectedUpdatedName, string expectedDescriptionName, bool expectedDefaultValue) { // Arrange IScopeRepository scopeRepository = new ScopeRepository(new SQLServerGateway(), new ConnectionStringData()); ScopeModel scopeModel = new ScopeModel(); scopeModel.Id = id; scopeModel.Type = expectedUpdatedName; scopeModel.Description = expectedDescriptionName; scopeModel.IsDefault = expectedDefaultValue; // Act await scopeRepository.UpdateScope(scopeModel); var actual = await scopeRepository.GetScopeById(id); var actualName = actual.Type; var actualDescriptionName = actual.Description; var actualDefaultValue = actual.IsDefault; // Assert Assert.IsTrue(actualName == expectedUpdatedName && actualDescriptionName == expectedDescriptionName && actualDefaultValue == expectedDefaultValue); }
public override void FuncPreInitCreateView() { //get article types var articleTypes = new ArticleTypeModel <ArticleType>().GetData(isBlock: false); ViewBag.ArticleTypes = articleTypes.Select(x => new CustomSelectListItem() { Text = x.ArticleTypeName, Value = x.ArticleTypeID.ToString() }); //get scopes var scopes = new ScopeModel <Scope>().GetData(isBlock: false); ViewBag.Scopes = scopes.Select(x => new CustomSelectListItem() { Text = x.ScopeName, Value = x.ScopeID.ToString() }); //get authors var authors = new AuthorModel <Author>().GetData(isBlock: false); ViewBag.Authors = authors.Select(x => new CustomSelectListItem() { Text = x.AuthorName, Value = x.AuthorID.ToString() }); base.FuncPreInitCreateView(); }
public DataResult <int> AddScopeToApiResource(int apiResourceId, ScopeModel scope, IEnumerable <int> claimsIds) { var newScope = new ScopeEntity { Name = scope.Name, Description = scope.Description, Required = scope.Required, ShowInDiscoveryDocument = scope.ShowInDiscoveryDocument }; try { var result = m_scopeUoW.AddScopeToApiResource(apiResourceId, newScope, claimsIds); return(Success(result)); } catch (NoResultException <ApiResourceEntity> e) { m_logger.LogWarning(e); return(Error <int>(m_translator.Translate("invalid-api-resource-id"), DataResultErrorCode.ApiResourceNotExistId)); } catch (DatabaseException e) { m_logger.LogWarning(e); return(Error <int>(e.Message)); } }
public async Task <IActionResult> EditScope(EditScopeViewModel scope) { // INCREMENT SCOPE VERSION var NewScope = new ScopeModel { ProjectId = scope.ProjectId, ParentScope = scope.ScopeParent, ScopeAuthor = scope.ScopeAuthor, ScopeExpectations = scope.UpdatedScopeExpectations, ScopeGoals = scope.UpdatedScopeGoals, ScopeLimitations = scope.UpdatedScopeLimitations, ScopeManager = scope.ScopeManager, ScopeSummary = scope.UpdatedScopeSummary, ScopeVersion = _context.Scopes.Where(S => S.ProjectId == scope.ProjectId).Count(), ScopeMaxPhaseNumber = scope.UpdatedScopePhaseNumberMax, ScopePhaseNumber = scope.UpdatedScopePhaseNum, ScopePhase = scope.UpdatedScopePhase, ScopeEndDate = scope.ScopeEndDate, ScopeStartDate = scope.ScopeStartDate, }; _context.Scopes.Add(NewScope); await _context.SaveChangesAsync(); ViewData["Msg"] = "Updated Scope and Added to Database"; return(RedirectToAction("Index")); }
public IActionResult DeleteScope(int apiId, int scopeId) { var scope = _configurationDbContext.Set <ApiScope>() .Include(x => x.ApiResource) .FirstOrDefault(x => x.Id == scopeId); return(View(ScopeModel.FromEntity(scope))); }
public void scope_model() { var scopeModel = NewScopeModel; var scopeModel2 = new ScopeModel(scopeModel.ToScope()); var scopeModel3 = NewScopeModel; scopeModel2.ShouldBe(scopeModel); scopeModel3.ShouldNotBe(scopeModel); }
public async Task Init() { await TestCleaner.CleanDatabase(); var numTestRows = 20; IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IScopeRepository scopeRepository = new ScopeRepository(dataGateway, connectionString); IResourceRepository resourceRepository = new ResourceRepository(dataGateway, connectionString); IClaimRepository claimRepository = new ClaimRepository(dataGateway, connectionString); IAccessPolicyRepository accessPolicyRepository = new AccessPolicyRepository(dataGateway, connectionString); IAccessPolicyPairingRepository accessPolicyPairingRepository = new AccessPolicyPairingRepository(dataGateway, connectionString); for (int i = 1; i <= numTestRows; ++i) { ResourceModel resourceModel = new ResourceModel(); resourceModel.Id = i; resourceModel.Name = "TestResource" + i; ScopeModel scopeModel = new ScopeModel(); scopeModel.Id = i; scopeModel.Type = "TestScope" + i; scopeModel.Description = "TestDescription" + i; ClaimModel claimModel = new ClaimModel(); claimModel.Id = i; claimModel.Type = "TestClaim" + i; claimModel.Value = "TestDescription" + i; claimModel.IsDefault = true; var resourceId = await resourceRepository.CreateResource(resourceModel); var claimId = await claimRepository.CreateClaim(claimModel); var scopeId = await scopeRepository.CreateScope(scopeModel); AccessPolicyModel accessPolicyModel = new AccessPolicyModel(); accessPolicyModel.Id = i; accessPolicyModel.Name = "TestAccessPolicy" + i; accessPolicyModel.ResourceId = resourceId; accessPolicyModel.Priority = i % 4; var accessPolicyId = await accessPolicyRepository.CreateAccessPolicy(accessPolicyModel); AccessPolicyPairingModel accessPolicyPairingModel = new AccessPolicyPairingModel(); accessPolicyPairingModel.Id = i; accessPolicyPairingModel.ScopeId = scopeId; accessPolicyPairingModel.ClaimId = claimId; accessPolicyPairingModel.AccessPolicyId = accessPolicyId; await accessPolicyPairingRepository.CreateAccessPolicyPairing(accessPolicyPairingModel); } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var source = (Scope)value; var target = new ScopeModel { Name = source.Name }; serializer.Serialize(writer, target); }
public IActionResult DeleteScope(ScopeModel model) { var api = _configurationDbContext.ApiResources .Include(x => x.Scopes) .FirstOrDefault(x => x.Id == model.ApiResourceId); var scope = api.Scopes.FirstOrDefault(x => x.Id == model.Id); api.Scopes.Remove(scope); _configurationDbContext.SaveChanges(); return(RedirectToAction(nameof(Scopes), new { id = api.Id })); }
public override void FuncPreInitEditView(object id, ref Scope EditItem, ref ScopeEditModel model) { if (EditItem == null) { //get the item by id EditItem = new ScopeModel <Scope>().Get(id); } if (EditItem != null) { model = new ScopeEditModel(); model.EditItem = EditItem; } }
/// <summary> /// SaveScope: Save scope into database. /// </summary> /// <param name="service"></param> /// <returns></returns> public int SaveScope(ScopeModel scope) { ScopeModel s = database.Table <ScopeModel>().Where(i => i.Id == scope.Id).FirstOrDefault(); if (s != null) { return(database.Update(scope)); } else { return(database.Insert(scope)); } }
public async Task <IActionResult> CreateScope(ScopeModel newScope) { Scope dupe = await _scopeService.Find(newScope.Name); if (dupe != null) { ModelState.AddModelError("FindScope", $"A scope with name {newScope.Name} already exists."); return(RedirectToAction("Index")); } await _scopeService.Save(newScope.IdsScope); return(RedirectToAction("Index")); }
public override void FuncPreDetailsView(object id, ref List <ScopeDetailsViewModel> items) { filters = new List <GenericDataFormat.FilterItems>(); filters.Add(new GenericDataFormat.FilterItems() { Property = "ScopeID", Operation = GenericDataFormat.FilterOperations.Equal, Value = id }); var requestBody = new GenericDataFormat() { Filters = filters }; items = new ScopeModel <ScopeDetailsViewModel>().Get(requestBody); }
public IActionResult AddScope(ScopeModel model) { var api = _configurationDbContext.ApiResources .Include(x => x.Scopes) .FirstOrDefault(x => x.Id == model.ApiResourceId); api.Scopes.Add(new ApiResourceScope { Scope = model.Scope }); _configurationDbContext.SaveChanges(); return(RedirectToAction(nameof(Scopes), new { id = api.Id })); }
public async Task <IActionResult> Edit(string scopeName, ScopeModel scope) { var editScope = await _scopeService.Find(scopeName); if (editScope == null) { ModelState.AddModelError("FindScope", $"Scope with the name {scopeName} could not be found."); return(RedirectToAction("Index")); } await _scopeService.Delete(scopeName); scope.IdsScope.Claims = editScope.Claims; await _scopeService.Save(scope.IdsScope); return(RedirectToAction("Index")); }
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); } }
/// <summary> /// SaveScope: Save scopes into database. /// </summary> /// <param name="scopes"></param> /// <returns></returns> public int SaveScope(List <ScopeModel> scopes) { int result = 0; foreach (ScopeModel scope in scopes) { ScopeModel s = database.Table <ScopeModel>().Where(i => i.Id == scope.Id).FirstOrDefault(); if (s != null) { result = database.Update(scope); } else { result = database.Insert(scope); } } return(result); }
public IActionResult EditScope(int apiId, int scopeId) { var api = _configurationDbContext.ApiResources .Include("Scopes.UserClaims") .FirstOrDefault(x => x.Id == apiId); if (scopeId != 0) { var scopeEntity = api.Scopes.FirstOrDefault(x => x.Id == scopeId); return(View(ScopeModel.FromEntity(scopeEntity))); } else { return(View(new ScopeModel { ApiResourceId = api.Id, ApiResourceName = api.Name, ApiResource = api, })); } }
public async Task Init() { await TestCleaner.CleanDatabase(); var numTestRows = 20; IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IScopeRepository scopeRepository = new ScopeRepository(dataGateway, connectionString); for (int i = 1; i <= numTestRows; ++i) { ScopeModel scopeModel = new ScopeModel(); scopeModel.Id = i; scopeModel.Type = "TestScope" + i; scopeModel.Description = "TestDescription" + i; scopeModel.IsDefault = true; await scopeRepository.CreateScope(scopeModel); } }
public async Task <int> UpdateScope(ScopeModel model) { try { var storedProcedure = "dbo.Scope_Update"; return(await _dataGateway.Execute(storedProcedure, new { Id = model.Id, type = model.Type, description = model.Description, isDefault = model.IsDefault }, _connectionString.SqlConnectionString)); } catch (SqlCustomException e) { throw new SqlCustomException("Scope could not be updated.", e.InnerException); } }
private void CreateConsentViewModel(string returnUrl, AuthorizationRequest request) { var model = this.Input; var check = model == null; var scopesConsented = model?.ScopesConsented.ToArray() ?? Array.Empty <string>(); this.Input = new InputModel { RememberConsent = model?.RememberConsent ?? true, ScopesConsented = scopesConsented, Description = model?.Description, ReturnUrl = returnUrl }; this.ClientName = request.Client.ClientName ?? request.Client.ClientId; this.ClientUrl = request.Client.ClientUri; this.ClientLogoUrl = request.Client.LogoUri; this.AllowRememberConsent = request.Client.AllowRememberConsent; this.IdentityScopes = ScopeModel.GetIdentityResourcesFromRequest(request.ValidatedResources, scopesConsented, check); this.ApiScopes = ScopeModel.GetApiScopeModelsFromRequest(request.ValidatedResources, scopesConsented, check); }
public async Task <int> CreateScope(ScopeModel model) { try { var storedProcedure = "dbo.Scope_Create"; DynamicParameters p = new DynamicParameters(); p.Add("type", model.Type); p.Add("description", model.Description); p.Add("isDefault", model.IsDefault); p.Add("Id", DbType.Int32, direction: ParameterDirection.Output); await _dataGateway.Execute(storedProcedure, p, _connectionString.SqlConnectionString); return(p.Get <int>("Id")); } catch (SqlCustomException e) { throw new SqlCustomException("Scope could not be created.", e.InnerException); } }
public async Task Init() { await TestCleaner.CleanDatabase(); var numTestRows = 20; IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IScopeRepository scopeRepository = new ScopeRepository(dataGateway, connectionString); IAssignmentPolicyRepository assignmentPolicyRepository = new AssignmentPolicyRepository(dataGateway, connectionString); IAssignmentPolicyPairingRepository assignmentPolicyPairingRepository = new AssignmentPolicyPairingRepository(dataGateway, connectionString); for (int i = 1; i <= numTestRows; ++i) { ScopeModel scopeModel = new ScopeModel(); scopeModel.Id = i; scopeModel.Type = "TestScope" + i; scopeModel.Description = "TestDescription" + i; var scopeId = await scopeRepository.CreateScope(scopeModel); scopeModel.IsDefault = true; AssignmentPolicyModel assignmentPolicyModel = new AssignmentPolicyModel(); assignmentPolicyModel.Id = i; assignmentPolicyModel.Name = "TestClaim" + i; assignmentPolicyModel.IsDefault = true; assignmentPolicyModel.RequiredAccountType = "TestAccountType" + i; assignmentPolicyModel.Priority = i % 4; var policyId = await assignmentPolicyRepository.CreateAssignmentPolicy(assignmentPolicyModel); AssignmentPolicyPairingModel assignmentPolicyPairingModel = new AssignmentPolicyPairingModel(); assignmentPolicyPairingModel.Id = i; assignmentPolicyPairingModel.PolicyId = policyId; assignmentPolicyPairingModel.ScopeId = scopeId; await assignmentPolicyPairingRepository.CreateAssignmentPolicyPairing(assignmentPolicyPairingModel); } }
public IActionResult EditScope(ScopeModel model) { var api = _configurationDbContext.ApiResources .Include("Scopes.UserClaims") .FirstOrDefault(x => x.Id == model.ApiResourceId); ApiScope scope; if (model.Id == 0) { scope = new ApiScope { UserClaims = new List <ApiScopeClaim>(), }; api.Scopes.Add(scope); } else { scope = api.Scopes.FirstOrDefault(x => x.Id == model.Id); scope.UserClaims.Clear(); } model.UpdateEntity(scope); if (!string.IsNullOrEmpty(model.UserClaimsItems)) { var userClaims = JsonConvert.DeserializeObject <List <string> >(model.UserClaimsItems); scope.UserClaims.AddRange(userClaims.Select(x => new ApiScopeClaim { Type = x, })); } _configurationDbContext.SaveChanges(); return(RedirectToAction(nameof(Scopes), new { id = api.Id })); }
public HttpResponseMessage Post(int id, ScopeModel model) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors())); } var app = config.Applications.All.SingleOrDefault(x => x.ID == id); if (app == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (app.Scopes.Any(x => x.Name == model.Name)) { ModelState.AddModelError("", "That Scope name is already in use."); return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.GetErrors())); } var scope = new Scope(); scope.Name = model.Name; scope.DisplayName = model.DisplayName; scope.Description = model.Description; scope.Emphasize = model.Emphasize; app.Scopes.Add(scope); config.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, new { scope.ID, scope.Name, scope.DisplayName, scope.Description, scope.Emphasize })); }
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 HelperCompleteRegister(RegisterUserModel user) { InitializeComponent(); currentService = 0; instance = this; NavigationPage.SetHasNavigationBar(this, false); currentUser = user; btnHelperRegSelectedService.isSelected = true; //btnHelperRegTbd.isSelected = false; entryHelperRegUsername1.Text = user.UserName; entryHelperRegPhone1.Text = user.MobileNumber; entryHelperRegEmail1.Text = user.Email; IEnumerable <string> genders = new List <string>() { "Male", "Female", "Rather no to say" }; SetRadioList(genders, rgHelperGender); //IEnumerable<String> locationTypes = new List<string>() { "Helper's Home", "Mobile Helper"}; //SetRadioList(locationTypes, rgHelperLocationType); IEnumerable <string> statusList = new List <string>() { "Available", "Not available" }; SetRadioList(statusList, rgHelperStatus); SetServices(); //if (user.IsServiced) // GoToBuildTrust(); //else //if (user.IsCompleted) // GoToEditServices(); //else //if (user.IsRegistered) //{ // GoToBasicInfo(); //} MessagingCenter.Subscribe <HelperRegister2, string>(this, "Current Address", (sender, currLoc) => { string[] locations = currLoc.Split(new char[] { ';' }); entryHelperRegLocation.Text = locations[0]; helperServices.Service[currentService].LocationName = locations[0]; helperServices.Service[currentService].Latitude = locations[1]; helperServices.Service[currentService].Longitude = locations[2]; }); MessagingCenter.Subscribe <HelperRegister3, string>(this, "Selected Address", (sender, selectedAddress) => { entryHelperRegLocation.Text = selectedAddress; }); MessagingCenter.Subscribe <ServiceButton, bool>(this, "Select Or Unselect Service", (sender, isSelected) => { try { string serviceName = ((ServiceButton)sender).serviceName; if (string.Equals(serviceName, "Hourly")) { if (((ServiceButton)sender).isSelected) { gridPriceHour.IsVisible = true; } else { gridPriceHour.IsVisible = false; } } else if (string.Equals(serviceName, "Daily")) { if (((ServiceButton)sender).isSelected) { gridPriceDay.IsVisible = true; } else { gridPriceDay.IsVisible = false; } } else if (string.Equals(serviceName, "Monthly")) { if (((ServiceButton)sender).isSelected) { gridPriceMonth.IsVisible = true; } else { gridPriceMonth.IsVisible = false; } } else { List <ServiceModel> services = App.Database.GetServices(); ServiceModel service = services.Where(a => a.ServiceName == serviceName).FirstOrDefault(); //var selectedService = helperServices.Service.Where(a => a.ServiceId == service.Id).FirstOrDefault(); int serviceIndex = services.IndexOf(service); var gService = gridServices.Children.Where(c => Grid.GetRow(c) == (serviceIndex) / 3 && Grid.GetColumn(c) == (serviceIndex) % 3); gService.ElementAt(1).IsVisible = !gService.ElementAt(1).IsVisible; if (isSelected) { AddGrid(gridHelperEditServices); HelperServices helperService = new HelperServices(); helperService.ServiceId = service.Id; helperService.ServiceName = service.ServiceName; helperServices.Service.Add(helperService); //selectedService.isSelected = true; //App.Database.SaveServiceAsync(selectedService); } else { int count = gridHelperEditServices.ColumnDefinitions.Count; for (int i = count - 1; i >= 0; i--) { gridHelperEditServices.ColumnDefinitions.RemoveAt(i); gridHelperEditServices.Children.RemoveAt(i); } for (int i = 0; i < count - 1; i++) { AddGrid(gridHelperEditServices); } HelperServices helperService = helperServices.Service.Where(a => a.ServiceId == service.Id).FirstOrDefault(); helperServices.Service.Remove(helperService); //selectedService.isSelected = false; //App.Database.SaveServiceAsync(selectedService); } var g = gridHelperEditServices.Children.Where(c => Grid.GetRow(c) == 0 && Grid.GetColumn(c) == 0).First(); g.BackgroundColor = Color.FromHex("#FF748C"); } } catch (Exception e) { Console.Write(e.StackTrace); } }); MessagingCenter.Subscribe <ScopeButton, bool>(this, "Select Or Unselect Service", (sender, isSelected) => { try { string scopeName = ((ScopeButton)sender).scopeName; List <ScopeModel> scopes = App.Database.GetScopes(); ScopeModel scope = scopes.Where(a => a.ScopeName == scopeName).FirstOrDefault(); if (isSelected) { HelperScopes helperScope = new HelperScopes() { ScopeId = scope.Id }; helperServices.Service[currentService].Scopes.Add(helperScope); } else { HelperScopes helperScope = helperServices.Service[currentService].Scopes.Where(x => x.ScopeId == scope.Id).FirstOrDefault(); helperServices.Service[currentService].Scopes.Remove(helperScope); } //App.Database.SaveScopeAsync(selectedScope); } catch (Exception e) { Console.Write(e.StackTrace); } }); }