//public async Task<Dictionary<int, Author>> GetAuthorsByIdAsync(IEnumerable<int> authorIds, CancellationToken token) // { // return await _libraryContext.Authors.Where(i => authorIds.Contains(i.AuthorId)).ToDictionaryAsync(x => x.AuthorId); // } public async Task <AuthorResponse> CreateAuthorAsync(AuthorCreateRequest author) { var addedAuthor = await _libraryContext.Authors.AddAsync(_mapper.Map <Author>(author)); await _libraryContext.SaveChangesAsync(); return(_mapper.Map <AuthorResponse>(addedAuthor.Entity)); }
public async Task <int> InsertAsync(AuthorCreateRequest dto) { var entity = new Author() { Name = dto.Name, Description = dto.Description, DateOfBirth = dto.DateOfBirth, CreatedAt = DateTime.Now, CreatedBy = "Ha Vi" }; return(await this._authorRepo.InsertAsync(entity)); }
public async Task <Response> CreateAuthor(AuthorCreateRequest request) { var response = new Response(); var AuthorToCreate = new Author() { Name = request.Name, Sex = request.Sex, Address = request.Address, BirthDate = request.BirthDate }; var result = await _repositoryCommand.Create(AuthorToCreate); response.Data = result; return(response); }
public async Task <IActionResult> Post([FromBody] AuthorCreateRequest model) { if (string.IsNullOrEmpty(model.Name)) { var error = new { Message = "Name is required!" }; return(this.BadRequest(error)); } var id = await this._authorService.InsertAsync(model); var result = new ApiResult <int>() { Message = "Insert success", Data = id }; return(this.Created("api/authors", result)); }
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)); }
public async Task <int> InsertAsync(AuthorCreateRequest dto) { var entity = new Author(dto.Name, dto.Description, dto.DateOfBirth); return(await this._authorRepo.InsertAsync(entity)); }
public async Task <IActionResult> Create(AuthorCreateRequest request) { return(Ok(await _authorService.CreateAuthor(request))); }