public async Task<HttpResponseMessage> Update(int id, DepartmentModel model) { try { int result = await service.UpdateAsync(Mapper.Map<IDepartment>(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(DepartmentModel dep) { try { int result = await service.AddAsync(Mapper.Map<IDepartment>(dep)); 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); } }