public async Task<HttpResponseMessage> Update(Guid id, TodoModel model) { try { int result = await service.UpdateAsync(Mapper.Map<ITodo>(model)); if (result >= 1) { return Request.CreateResponse(HttpStatusCode.OK, model); } else { return Request.CreateResponse(HttpStatusCode.BadRequest, "Error while trying to edit task."); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } }
public async Task<HttpResponseMessage> Insert(TodoModel todo) { try { int result = await service.AddAsync(Mapper.Map<ITodo>(todo)); if (result == 0) { return Request.CreateResponse(HttpStatusCode.BadRequest, "Add operation error."); } else { return Request.CreateResponse(HttpStatusCode.OK, result); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } }