public async Task <IActionResult> AddHttpResolver(HttpResolver postHttpResolver) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (ModelState.IsValid) { Assignment assignment = await _context.Assignments.FindAsync(postHttpResolver.AssignmentId); if (assignment == null) { NotFound(); } else if (!await _context.ManagesAgency(userId, assignment.AgencyId)) { return(Forbid()); } // ensure the resolver does not already exist HttpResolver resolver = new HttpResolver(); resolver.AssignmentId = postHttpResolver.AssignmentId; resolver.ResolutionType = postHttpResolver.ResolutionType; resolver.UrlTemplate = postHttpResolver.UrlTemplate; _context.HttpResolvers.Add(resolver); await _context.SaveChangesAsync(); return(RedirectToAction("EditAssignment", "Manage", new { assignmentId = assignment.AssignmentId })); } return(View(postHttpResolver)); }
public async Task <IActionResult> DeleteHttpResolver(HttpResolver postHttpResolver) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; HttpResolver resolver = await _context.HttpResolvers.FindAsync(postHttpResolver.Id); if (resolver == null) { return(NotFound()); } Assignment assignment = await _context.Assignments.FindAsync(resolver.AssignmentId); if (assignment == null) { NotFound(); } else if (!await _context.ManagesAgency(userId, assignment.AgencyId)) { return(Forbid()); } _context.HttpResolvers.Remove(resolver); await _context.SaveChangesAsync(); return(RedirectToAction("EditAssignment", "Manage", new { assignmentId = assignment.AssignmentId })); }
public async Task <IActionResult> EditHttpResolver(string resolverId) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (!await _context.ManagesHttpResolver(userId, resolverId)) { return(Forbid()); } HttpResolver service = await _context.HttpResolvers.FindAsync(resolverId); return(View(service)); }
public void CanResolveResource() { var resourcePath = "http://example.com"; var httpResolver = new HttpResolver(); var path = httpResolver.Resolve(resourcePath); Assert.AreEqual(_htmlContent, File.ReadAllText(path)); TempFileResolutionCache.Clear(); Assert.False(File.Exists(path)); }
public void CanResolveResource_Reuses_Previous_Temp_File() { var resourcePath = "http://example.com"; var embeddedResourceResolver = new HttpResolver(); var path = embeddedResourceResolver.Resolve(resourcePath); var path2 = embeddedResourceResolver.Resolve(resourcePath); Assert.AreEqual(_htmlContent, File.ReadAllText(path)); Assert.AreEqual(_htmlContent, File.ReadAllText(path2)); Assert.AreEqual(path, path2); TempFileResolutionCache.Clear(); Assert.False(File.Exists(path)); }
public async Task <IActionResult> AddHttpResolver(string assignmentId) { //RegistryProvider provider = new RegistryProvider(); //string username = User.Identity.Name; var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; Assignment assignment = await _context.Assignments.FindAsync(assignmentId); if (assignment == null || !await _context.ManagesAgency(userId, assignment.AgencyId)) { return(Forbid()); } HttpResolver resolver = new HttpResolver() { AssignmentId = assignmentId }; return(View(resolver)); }
public async Task <IActionResult> EditHttpResolver(HttpResolver postHttpResolver) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (ModelState.IsValid) { if (!await _context.ManagesHttpResolver(userId, postHttpResolver.Id)) { return(Forbid()); } var resolver = await _context.HttpResolvers.FindAsync(postHttpResolver.Id); resolver.AssignmentId = postHttpResolver.AssignmentId; resolver.ResolutionType = postHttpResolver.ResolutionType; resolver.UrlTemplate = postHttpResolver.UrlTemplate; await _context.SaveChangesAsync(); Assignment assignment = await _context.Assignments.FindAsync(resolver.AssignmentId); return(RedirectToAction("ViewAgency", "Manage", new { agencyId = assignment.AgencyId })); } return(View(postHttpResolver)); }
public async Task <IActionResult> DeleteHttpResolver(string resolverId) { //RegistryProvider provider = new RegistryProvider(); //string username = User.Identity.Name; var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; HttpResolver resolver = await _context.HttpResolvers.FindAsync(resolverId); if (resolver == null) { return(NotFound()); } Assignment assignment = await _context.Assignments.FindAsync(resolver.AssignmentId); if (assignment == null) { NotFound(); } else if (!await _context.ManagesAgency(userId, assignment.AgencyId)) { return(Forbid()); } return(View(resolver)); }