public async Task <IActionResult> UpdateAuthor([FromBody] UpdateAuthorRequest request) { Author author = await _authorService.GetById(request.Id); author.Name = request.Name; _authorService.Update(author); return(Ok()); }
public static UpdateAuthorRequest ConvertToUpdateAuthorRequest(this AuthorViewModel model) { UpdateAuthorRequest request = new UpdateAuthorRequest(); request.AuthorId = Convert.ToInt32(model.AuthorId); request.Name = model.Name; request.NationalityId = model.Nationality.NationalityId; return(request); }
public static Author ConvertToAuthor(this UpdateAuthorRequest updateRequest) { Author author = new Author(); author.AuthorId = updateRequest.AuthorId; author.Name = updateRequest.Name; author.Nationality = new Nationality() { NationalityId = updateRequest.NationalityId }; return(author); }
public void UpdateAuthor(UpdateAuthorRequest request) { if (!new UpdateAuthorRequestValidator().Validate(request).IsValid) { throw new Exception("UpdateAuthor validation error"); } Persistence.BeginTransaction(); var author = GetAuthorById(request.Id); author.Update(request); Persistence.Commit(); }
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))); }
public async Task <IActionResult> UpdateAsync([FromRoute] int authorId, [FromBody] UpdateAuthorRequest request) { var author = await this.authorService.GetAuthorByIdAsync(authorId); author.FullName = request.FullName; author.Biography = request.Biography; var updated = await this.authorService.UpdateAuthorAsync(author); if (!updated) { return(this.NotFound()); } return(this.Ok(author)); }
public async Task <Response> UpdateAuthor(UpdateAuthorRequest request) { var response = new Response(); var UpdateToMake = new Author() { Name = request.Name, Sex = request.Sex, Address = request.Address, BirthDate = request.BirthDate }; var result = await _repositoryCommand.Update(UpdateToMake); response.Data = result; return(response); }
public ActionResult Edit(AuthorSinglePageViewModel model) { UpdateAuthorRequest request = model.AuthorViewModel.ConvertToUpdateAuthorRequest(); UpdateAuthorResponse response = _authorService.UpdateAuthor(request); if (response.Success) { return(RedirectToAction("Index")); } else { model.Success = false; model.Message = response.Message; return(View(model)); } }
public UpdateTest(CustomWebApplicationFactory factory, ITestOutputHelper output) : base(factory) { _faker = new Faker("pt_BR"); _output = output; _updateAuthorRequest = new UpdateAuthorRequest { FirstName = _faker.Person.FirstName, LastName = _faker.Person.LastName, Username = _faker.Person.UserName, Email = _faker.Person.Email, Avatar = _faker.Person.Avatar, Bio = _faker.Lorem.Text() }; }
public UpdateAuthorResponse UpdateAuthor(UpdateAuthorRequest request) { UpdateAuthorResponse response = new UpdateAuthorResponse(); try { Author author = request.ConvertToAuthor(); _authorRepository.Update(author); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public void UpdateAuthor(UpdateAuthorRequest request) { if (ModelState.IsValid == false) { throw new ArgumentException(); } // データベースに登録する using (var pubs = new PubsEntities()) { var target = pubs.Authors.FirstOrDefault(a => a.AuthorId == request.AuthorId); target.AuthorFirstName = request.AuthorFirstName; target.AuthorLastName = request.AuthorLastName; target.Phone = request.Phone; target.State = request.State; pubs.SaveChanges(); } }
public async Task <IActionResult> Update([FromRoute] Guid authorId, [FromBody] UpdateAuthorRequest request) { if (!ModelState.IsValid) { return(BadRequest(new ErrorResponse { Errors = ModelState.Values.SelectMany(x => x.Errors.Select(e => e.ErrorMessage)) })); } var author = await _authorService .GetAuthorByIdAsync(authorId) .ConfigureAwait(false); if (author == null) { return(NotFound()); } author.FirstName = request?.FirstName; author.LastName = request?.LastName; author.Username = request?.Username; author.Email = request?.Email; author.Bio = request?.Bio; author.Avatar = request?.Avatar; var updated = await _authorService .UpdateAuthorAsync(author) .ConfigureAwait(false); if (!updated) { return(NotFound()); } var authorResponse = new Response <AuthorResponse>( _mapper.Map <AuthorResponse>(author)); return(Ok(authorResponse)); }
public async Task <IActionResult> UpdateAuthor(int libraryId, int authorId, [FromBody] AuthorView author, CancellationToken token = default(CancellationToken)) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } var request = new UpdateAuthorRequest(libraryId, author.Map()); await _commandProcessor.SendAsync(request, cancellationToken : token); var renderResult = _authorRenderer.Render(request.Result.Author, libraryId); if (request.Result.HasAddedNew) { return(new CreatedResult(renderResult.Links.Self(), renderResult)); } else { return(new OkObjectResult(renderResult)); } }
public virtual void Update(UpdateAuthorRequest request) { HandleAuthorRequest(request); }
public async Task <IActionResult> Update(UpdateAuthorRequest request) { return(Ok(await _authorService.UpdateAuthor(request))); }