public async Task UpdateAsync(Guid ticketId, PutTicketDTO ticket) { try { var ticketInDb = await db.Tickets.FirstOrDefaultAsync(f => f.Id == ticketId); if (ticketInDb == null) { throw new EntityNotFoundException(); } //admins can edit any ticket //others just can edit a ticket if the ticket is opened by them ThrowIfUserIsNotTheCreatorOfTheTicket(appUser, ticketInDb); var mappedEntity = mapper.Map(ticket, ticketInDb); db.Update(ticketInDb); await db.SaveChangesAsync(); } catch (Exception ex) { throw; } }
public async Task <ApiResponse> Put(string id, [FromBody] PutTicketDTO arg) { try { await ticketService.UpdateAsync(id.ToGuid(), arg); return(new ApiResponse(InfoMessages.TicketUpdated, null, HttpStatusCode.OK.ToInt())); } catch (ValidationException ex) { throw new ApiException(ex.Errors, ex.StatusCode); } catch (CustomException ex) { throw new ApiException(ex, ex.StatusCode); } catch (Exception ex) { throw new ApiException(ex); } }