public async Task <IActionResult> AddAuthorAsync([FromBody] CreateAuthorRequest AuthorRequest) { (bool succeed, string message, CreateAuthorResponse AuthorResponse) = await Mediator.Send(AuthorRequest); if (succeed) { return(Ok(AuthorResponse.ToResponse())); } return(BadRequest(message.ToResponse(false, message))); }
public async Task <ActionResult <AuthorDetailResource> > DeleteAuthor(int id) { AuthorResponse response = await _authorService.DeleteAsync(id); if (!response.Success) { return(BadRequest(response.Message)); } AuthorDetailResource deletedResource = _mapper.Map <AuthorDetailResource>(response.Author); return(Ok(deletedResource)); }
public async Task <ActionResult <AuthorDetailResource> > GetAuthor(int id) { AuthorResponse response = await _authorService.FindByIdAsync(id); if (!response.Success) { return(NotFound(response.Message)); } AuthorDetailResource resource = _mapper.Map <AuthorDetailResource>(response.Author); return(Ok(resource)); }
public IActionResult GetAuthor(Guid id) { var authorFromRepo = _libraryRepository.GetAuthor(id); if (authorFromRepo == null) { return(NotFound()); } var author = new AuthorResponse(authorFromRepo); return(Ok(author)); }
public async Task <ActionResult <AuthorDetailResource> > PutAuthor(int id, AuthorSaveResource resource) { Author author = _mapper.Map <Author>(resource); AuthorResponse response = await _authorService.UpdateAsync(id, author); if (!response.Success) { return(BadRequest(response.Message)); } AuthorDetailResource updatedResource = _mapper.Map <AuthorDetailResource>(response.Author); return(Ok(updatedResource)); }
public async Task <ActionResult <AuthorDetailResource> > PostAuthor(AuthorSaveResource resource) { Author author = _mapper.Map <Author>(resource); AuthorResponse response = await _authorService.SaveAsync(author); if (!response.Success) { return(BadRequest(response.Message)); } AuthorDetailResource savedResource = _mapper.Map <AuthorDetailResource>(response.Author); return(CreatedAtAction(nameof(GetAuthor), new { id = savedResource.Id }, savedResource)); }
public async Task <IActionResult> UpdateAuthorAsync([FromBody] UpdateAuthorRequest AuthorRequest) { UpdateAuthorRequest update = new UpdateAuthorRequest(); update = AuthorRequest; (bool succeed, string message, UpdateAuthorResponse AuthorResponse) = await Mediator.Send(update); if (succeed) { return(Ok(AuthorResponse.ToResponse())); } return(BadRequest(message.ToResponse(false, message))); }
private static void WriteAuthorsFile(string filename, AuthorResponse authorLookup) { AuthorResponse outpuAuthors = new AuthorResponse(); outpuAuthors.Authors = authorLookup.Authors.OrderBy(a => a.Name).ToList(); string authorJson = JsonConvert.SerializeObject(outpuAuthors, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); File.WriteAllText(filename, authorJson); }
private async Task EnsureAuthorIsCorrectOnDatabaseAsync(AuthorResponse authorResponse) { var options = new DbContextOptionsBuilder <ControllerTestingDbContext>() .UseSqlServer(_configuration.GetConnectionString("DefaultConnection")) .Options; using var dbContext = new ControllerTestingDbContext(options); var dbAuthor = await dbContext.Authors .Where(author => author.Id == authorResponse.Id) .FirstOrDefaultAsync(); authorResponse.Id.Should().Be(dbAuthor.Id); authorResponse.FirstName.Should().Be(dbAuthor.FirstName); authorResponse.LastName.Should().Be(dbAuthor.LastName); authorResponse.DateOfBirth.Date.Should().Be(dbAuthor.DateOfBirth.Date); }
private static AuthorResponse LoadAuthorLookup(string authorsPath) { if (File.Exists(authorsPath)) { var json = File.ReadAllText(authorsPath); var authorResponse = JsonConvert.DeserializeObject <AuthorResponse>(json); return(authorResponse); } else { // create a new author response object var authorResponse = new AuthorResponse(); authorResponse.Authors = new List <Author>(); return(authorResponse); } }
public IActionResult CreateAuthor([FromBody] AuthorCreateRequest author) { if (author == null) { return(BadRequest()); } var authorEntity = author.ConvertToAuthor(); _libraryRepository.AddAuthor(authorEntity); if (!_libraryRepository.Save()) { throw new Exception("Creating an author failed on save."); } var authorToReturn = new AuthorResponse(authorEntity); return(CreatedAtRoute("GetAuthor", new { id = authorToReturn.Id }, authorToReturn)); }
static void Main(string[] args) { // work out our paths // TODO: These should probably by derived from args string executeLocation = System.Reflection.Assembly.GetExecutingAssembly().Location; basePath = System.IO.Path.GetDirectoryName(executeLocation); outputPath = Path.Combine(basePath, "Output"); curatedDataPath = Path.Combine(basePath, "CuratedExport"); lookupDataPath = Path.Combine(basePath, "LookupData"); // for debug override the basepath basePath = @"D:\GitHub\weeklyxamarin\WeeklyXamarin.content\content"; outputPath = basePath; curatedDataPath = @"D:\github\WeeklyXamarin\WeeklyXamarin.content\curateddata\published"; planetXamarinAuthorsDataPath = @"D:\github\planetxamarin\planetxamarin\src\Firehose.Web\Authors"; lookupDataPath = basePath; // load up the editions from curated files CuratedEditions = LoadupCuratedEditions(curatedDataPath); // create the index file - before we have the articles Core.Models.Index indexLookup = LoadIndexFile(Path.Combine(lookupDataPath, IndexFile)); UpdateIndexFile(indexLookup, CuratedEditions); WriteIndexFile(Path.Combine(outputPath, IndexFile), indexLookup); // load up the authors lookup file which is used // to try and identify authors via multiple means AuthorLookup = LoadAuthorLookup(Path.Combine(lookupDataPath, AuthorsFile)); ProcessEditions(); //ProcessPlanetXamarinAuthors(); // finally we have an authors WriteAuthorsFile(Path.Combine(outputPath, AuthorsFile), AuthorLookup); OutputEditions(outputPath, Editions); }
public AuthorByBookIdResponse(AuthorResponse author, bool isAuthor) { Author = author; IsAuthor = isAuthor; }
public static string GetFullname(this AuthorResponse authorResponse) => $"{authorResponse.Lastname}, {authorResponse.Firstname}";