Exemplo n.º 1
0
        public IActionResult RealPut(int id, [FromBody] ChangeTicketDto dto
                                     , [FromServices] IChangeTicketCommand command
                                     , [FromServices] ChangeTicketValidator validator)
        {
            dto.Id = id;
            var result = validator.Validate(dto);

            if (result.IsValid)
            {
                Ticket ticket = _mapper.Map <Ticket>(dto);
                _useCaseExecutor.ExecuteCommand(command, ticket);
                return(Ok("Ticket changed successfully"));
            }

            return(UnprocessableEntity(UnprocessableEntityResponse.Message(result.Errors)));
        }
Exemplo n.º 2
0
        public IActionResult FakePut(int id, [FromBody] ChangeTicketDto dto
                                     , [FromServices] IAddTicketCommand command
                                     , [FromServices] ChangeTicketValidator validator)
        {
            dto.Id = id; //Add id to dto to validate if item exists
            var result = validator.Validate(dto);

            if (result.IsValid)
            {
                Ticket ticket = _mapper.Map <Ticket>(dto);
                ticket.OriginalTicketId = id;
                ticket.Id = default; //set default value for int (0), because new instance will be created
                _useCaseExecutor.ExecuteCommand(command, ticket);
                return(Ok("Ticket changed successfully"));
            }

            return(UnprocessableEntity(UnprocessableEntityResponse.Message(result.Errors)));
        }