public async Task <IActionResult> Handle(PartiallyUpdateTicketCommand request, CancellationToken cancellationToken) { var spec = new TicketsWithCommentsAndDevelopersSpecification(request.TicketId); var ticket = await _unitOfWork.Repository <Ticket>().GetEntityWithSpecification(spec); if (ticket == null) { return(request.Controller.NotFound(new ApiResponse(404))); } var ticketToPatch = _mapper.Map <TicketForUpdateDto>(ticket); request.PatchDocument.ApplyTo(ticketToPatch, request.Controller.ModelState); if (!request.Controller.TryValidateModel(ticketToPatch)) { return(request.Controller.ValidationProblem(request.Controller.ModelState)); } var updatedTicket = _mapper.Map(ticketToPatch, ticket); try { _unitOfWork.Repository <Ticket>().Update(updatedTicket); await _unitOfWork.Complete(); } catch (Exception ex) { return(new ObjectResult(new ApiException(500, ex.Message))); } return(request.Controller.NoContent()); }
public async Task <TicketDto> Handle(GetTicketByIdQuery request, CancellationToken cancellationToken) { var spec = new TicketsWithCommentsAndDevelopersSpecification(request.TicketId); var ticket = await _unitOfWork.Repository <Ticket>().GetEntityWithSpecification(spec); return(ticket == null ? null : _mapper.Map <Ticket, TicketDto>(ticket)); }
public async Task <Pagination <TicketDto> > Handle(GetAllTicketsQuery request, CancellationToken cancellationToken) { var spec = new TicketsWithCommentsAndDevelopersSpecification(request.TicketParameters); var countSpec = new TicketWithFiltersForCountSpecification(request.TicketParameters); var tickets = await _unitOfWork.Repository <Ticket>().ListAsync(spec); var totalItems = await _unitOfWork.Repository <Ticket>().CountAsync(countSpec); var data = _mapper.Map <IReadOnlyList <Ticket>, IReadOnlyList <TicketDto> >(tickets); return(new Pagination <TicketDto>(request.TicketParameters.PageIndex, request.TicketParameters.PageSize, totalItems, data)); }