public static void ToUpdateEntity(this AuthorUpdateRequest request, ref AuthorEntity author) { if (request == null || author == null) { return; } if (!string.IsNullOrEmpty(request.FirstName)) { author.FirstName = request.FirstName; } if (!string.IsNullOrEmpty(request.LastName)) { author.LastName = request.LastName; } if (!string.IsNullOrEmpty(request.LastName)) { author.MainCategory = request.MainCategory; } if (!string.IsNullOrEmpty(request.LastName)) { author.DateOfBirth = request.DateOfBirth; } }
public async Task Update(AuthorUpdateRequest dto) { var data = await this._authorRepo.GetAsync(dto.Id); data.Name = dto.Name; data.Description = dto.Description; var result = await this._authorRepo.UpdateAsync(data); }
public async Task <ActionResult <AuthorDto> > UpdateAuthor(Guid authorId, [FromBody] AuthorUpdateRequest authorRequest) { AuthorDto author = await _authorService.UpdateAuthorAsync(authorId, authorRequest); if (author == null) { return(NotFound()); } return(Ok(author)); }
public AuthorResponse UpdateAuthor(int authorId, AuthorUpdateRequest author) { var authorToUpdate = _mapper.Map <Author>(author); authorToUpdate.AuthorId = authorId; var updatedAuthor = _libraryContext.Authors.Update(authorToUpdate); _libraryContext.SaveChanges(); return(_mapper.Map <AuthorResponse>(updatedAuthor.Entity));; }
public async Task <IActionResult> Put(int id, [FromBody] AuthorUpdateRequest model) { var data = await this._authorService.GetById(id); if (data == null) { return(BadRequest(new { error = "Data is not exist" })); } await this._authorService.Update(model); var result = new ApiResult <AuthorDetailResponse>() { Message = "update success", Data = null }; return(Ok(result)); }
public async Task <AuthorDto> UpdateAuthorAsync(Guid authorId, AuthorUpdateRequest authorRequest) { if (authorId == Guid.Empty) { throw new ArgumentNullException(nameof(authorId)); } AuthorEntity author = await _context.Authors.FirstOrDefaultAsync(x => x.Id == authorId); if (author == null) { return(null); } authorRequest.ToUpdateEntity(ref author); await _context.SaveChangesAsync(); return(author.ToDto()); }
} // AuthorSelect public static void AuthorUpdate(AuthorUpdateRequest payload) { AuthorUpdate(payload.ID, payload.Email); } //AuthorUpdate