예제 #1
0
        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)));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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));
        }
예제 #5
0
        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));
        }
예제 #6
0
        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));
        }
예제 #7
0
        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)));
        }
예제 #8
0
        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);
        }
예제 #10
0
        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));
        }
예제 #12
0
        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);
        }
예제 #13
0
 public AuthorByBookIdResponse(AuthorResponse author, bool isAuthor)
 {
     Author   = author;
     IsAuthor = isAuthor;
 }
예제 #14
0
 public static string GetFullname(this AuthorResponse authorResponse)
 => $"{authorResponse.Lastname}, {authorResponse.Firstname}";