public async Task <HttpResponseMessage> Put(string id, RecipeAlergenModel entity) { try { if (id != entity.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "IDs do not match.")); } var result = await Service.UpdateAsync(Mapper.Map <IRecipeAlergen>(entity)); if (result == 1) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "PUT unsuccessful.")); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e.ToString())); } }
public async Task <HttpResponseMessage> Post(RecipeAlergenModel entity) { entity.Id = Guid.NewGuid().ToString(); try { var result = await Service.InsertAsync(Mapper.Map <IRecipeAlergen>(entity)); if (result == 1) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "POST unsuccessful.")); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e.ToString())); } }