Exemple #1
0
        public async Task<HttpResponseMessage> Post(TicketModel inputModel)
        {
            var me = await _db.Users.FirstAsync();
            
            var ticket = new Ticket(inputModel.Title, TicketPriority.Medium, me);

            _db.Tickets.Add(ticket);
            await _db.SaveChangesAsync();

            var response = new HttpResponseMessage(HttpStatusCode.Created);
            response.Headers.Location = new Uri("/api/tickets/" + ticket.TicketId, UriKind.Relative);

            return response;
        }
Exemple #2
0
 public async Task<HttpResponseMessage> Put(TicketModel inputModel)
 {
     var ticket = await _db.Tickets.FirstAsync(x => x.TicketId == inputModel.TicketId);
     Mapper.Map(inputModel, ticket);
     try
     {
         await _db.SaveChangesAsync();
     }
     catch (Exception e)
     {
         var message = new HttpResponseMessage(HttpStatusCode.InternalServerError);
         message.Content = new StringContent(e.Message);
         return message;
     }
     return new HttpResponseMessage(HttpStatusCode.OK);
 }