Ejemplo n.º 1
0
        public async Task <IActionResult> TicketUpdate([FromRoute] long id, [FromBody] PatchTicketRequest request)
        {
            var keyAuthResult = await _authService.AuthByApiKey();

            if (keyAuthResult.User == null)
            {
                return(BadRequest(ErrorResponse.GetErrorList(keyAuthResult.ErrorText)));
            }

            var ticket = _ticketService.GetTicket(id);

            if (ticket == null)
            {
                return(NotFound(ErrorResponse.GetErrorList($"Ticket with id {id} was not found!")));
            }

            if (!await _authService.AuthorizeProjectRole(eProjectRoles.Reporter, ticket.ProjectId, user: keyAuthResult.User))
            {
                return(Unauthorized(ErrorResponse.GetUnauthorizedErrorList(keyAuthResult.User.Identity.Name, ticket.Project.Name, eProjectRoles.Reporter)));
            }

            ticket = _ticketService.UpdateTicket(id, request.State, request.Type, request.AssignedTo);

            if (ticket == null)
            {
                return(NotFound(ErrorResponse.GetErrorList($"Ticket with id {id} was not found!")));
            }

            var response = _mapper.Map <TicketResponse>(ticket);

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task Tickets_UpdateTicket_TicketExists_ExpectsUpdated()
        {
            var client = getClient();

            var createdTicket = await createTicket(client);

            PatchTicketRequest patchRequest = new PatchTicketRequest()
            {
                State = eTicketState.Denied,
            };

            Assert.NotEqual(patchRequest.State, createdTicket.State);

            var response = await client.PatchAsJsonAsync(ApiRoutes.Tickets.Update.Replace("{id}", createdTicket.Id.ToString()), patchRequest);

            var responseTicket = await response.Content.ReadAsAsync <TicketResponse>();

            Assert.Equal(patchRequest.State, responseTicket.State);
        }