Example #1
0
        public async Task <IActionResult> UpdateAuthor([FromBody] UpdateAuthorRequest request)
        {
            Author author = await _authorService.GetById(request.Id);

            author.Name = request.Name;
            _authorService.Update(author);
            return(Ok());
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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();
        }
Example #5
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)));
        }
Example #6
0
        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));
        }
Example #7
0
        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);
        }
Example #8
0
        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));
            }
        }
Example #9
0
        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()
            };
        }
Example #10
0
        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();
            }
        }
Example #12
0
        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));
        }
Example #13
0
        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));
            }
        }
Example #14
0
 public virtual void Update(UpdateAuthorRequest request)
 {
     HandleAuthorRequest(request);
 }
 public async Task <IActionResult> Update(UpdateAuthorRequest request)
 {
     return(Ok(await _authorService.UpdateAuthor(request)));
 }