Exemplo n.º 1
0
        public async Task <IActionResult> Put([FromBody] AuthorUpdateCommand request)
        {
            // todo: check if newer on server ..
            var result = await Mediator.Send(request);

            return(FromCQRS(result));
        }
        public async Task <IActionResult> AuthorUpdate([FromRoute] Guid authorId, [FromBody] AuthorUpdateCommand command)
        {
            command.Id = authorId;
            await _mediator.DispatchAsync(command);

            return(NoContent());
        }
Exemplo n.º 3
0
            public async Task <CQRSResult <AuthorGetDTO> > Handle(AuthorUpdateCommand request, CancellationToken cancellationToken)
            {
                var exists = uow.AuthorsRepository.Contains(x => x.Id == request.Id);

                if (exists)
                {
                    var entity = mapper.Map <Author>(request);
                    uow.AuthorsRepository.Update(entity);
                    await uow.Save();

                    return(mapper.Map <AuthorGetDTO>(entity));
                }
                else
                {
                    return(mapper.Map <AuthorGetDTO>(request).AsResult(code: 404));
                }
            }
Exemplo n.º 4
0
            public async Task <CQRSResult <AuthorGetDTO> > Handle(AuthorUpdateCommand request, CancellationToken cancellationToken)
            {
                var exists = uow.AuthorsRepository.Contains(x => x.Id == request.Id);

                if (exists)
                {
                    var entity = request.ToModel();
                    uow.AuthorsRepository.Update(entity);
                    await uow.Save();

                    return(AuthorGetMap.ToDTO(entity));
                }
                else
                {
                    return((null as AuthorGetDTO).AsCQRSResult(code: 404));
                }
            }
        public async Task <IActionResult> Put(string id, [FromBody] AuthorUpdateCommand command)
        {
            try
            {
                if (id != command.Id)
                {
                    return(NotFound(id));
                }
                if (ModelState.IsValid)
                {
                    var model = await Mediator.Send(command);

                    return(model ? Ok(model) : StatusCode(304, model));
                }
                return(BadRequest());
            }
            catch (Exception)
            {
                throw;
            }
        }