public async Task <IActionResult> Create(ReferenceSourceLibraryModel libraryModel) { try { ReferenceSourceLibrary library = new ReferenceSourceLibrary { Id = libraryModel.Id, Name = libraryModel.Name, Description = libraryModel.Description, Location = libraryModel.Location, SupportedDotNetVersions = libraryModel.SupportedDotNetVersions }; libraryModel.ReferenceAssemblies.ForEach(async RA => { library.Add(await _context.GetReferenceAssembly(RA)); }); libraryModel.EmbeddedResources.ForEach(async ER => { library.Add(await _context.GetEmbeddedResource(ER)); }); ViewBag.ReferenceAssemblies = await _context.GetReferenceAssemblies(); ViewBag.EmbeddedResources = await _context.GetEmbeddedResources(); ReferenceSourceLibrary createdLibrary = await _context.CreateReferenceSourceLibrary(libraryModel); return(RedirectToAction(nameof(Edit), new { Id = createdLibrary.Id })); } catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException) { ViewBag.ReferenceAssemblies = await _context.GetReferenceAssemblies(); ViewBag.EmbeddedResources = await _context.GetEmbeddedResources(); return(View(new ReferenceSourceLibrary())); } }
public async Task <ActionResult <ReferenceSourceLibrary> > CreateReferenceSourceLibrary([FromBody] ReferenceSourceLibrary library) { try { ReferenceSourceLibrary createdLibrary = await _context.CreateReferenceSourceLibrary(library); return(CreatedAtRoute(nameof(GetReferenceSourceLibrary), new { id = createdLibrary.Id }, createdLibrary)); } catch (ControllerNotFoundException e) { return(NotFound(e.Message)); } catch (ControllerBadRequestException e) { return(BadRequest(e.Message)); } catch (ControllerUnauthorizedException) { return(new UnauthorizedResult()); } }