public HttpResponseMessage PostIngredient(Ingredient ingredient) { if (ModelState.IsValid) { _repository.Add(ingredient); var response = Request.CreateResponse(HttpStatusCode.Created, ingredient); response.Headers.Location = new Uri(Url.Link("~/api/ingredient/", new { id = ingredient.Id })); return response; } return Request.CreateResponse(HttpStatusCode.BadRequest); }
public static DietIngredient CreateDietIngredient(Diet diet, Ingredient ingredient) { return new DietIngredient { Day = "0,1", Diet = diet, Ingredient = ingredient, IngredientId = ingredient.Id, Quantity = 2, Time = 900, QuantityType = new QuantityType {Id = 3, Name = "Test", IsDeleted = false}, QuantityTypeId = 3 }; }
public HttpResponseMessage PutIngredient(int id, Ingredient ingredient) { if (ModelState.IsValid && id == ingredient.Id) { try { _repository.Update(id, ingredient); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK, ingredient); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public static Meal CreateOatMeal() { var milk = new Ingredient { Carb = 4.7, Fat = 0.7, Protein = 3.3, Kcal = 38, Name = "Melk", Id = 4 }; var whey = new Ingredient { Carb = 0.4, Fat = 3, Protein = 86, Kcal = 360, Name = "Whey-100" }; var oatMeal = new Ingredient { Carb = 61, Fat = 7, Protein = 13, Kcal = 365, Name = "Havregryn" }; var meal = new Meal { Name = "HavreShake" }; var glass = new QuantityType { Name = "Glass", Id = 14 }; var mealIngredientMilk = new MealIngredient { Ingredient = milk, IngredientId = 4, Meal = meal, Quantity = 1.2, QuantityType = glass, QuantityTypeId = 14 }; var gram = new QuantityType { Name = "Gram", Id = 1 }; var mealIngredientWhey = new MealIngredient { Ingredient = whey, IngredientId = 5, Meal = meal, Quantity = 37, QuantityType = gram, QuantityTypeId = 1 }; var mealIngredientOatMeal = new MealIngredient { Ingredient = oatMeal, IngredientId = 6, Quantity = 40, QuantityType = gram, Meal = meal, QuantityTypeId = 1 }; meal.MealIngredients = new List<MealIngredient> { mealIngredientMilk, mealIngredientOatMeal, mealIngredientWhey }; return meal; }
public static MealIngredient CreateMealIngredients(Meal meal, Ingredient ingredient, QuantityType quantityType) { return new MealIngredient { MealId = meal.Id, IngredientId = ingredient.Id, Ingredient = ingredient, Meal = meal, Quantity = 3, Optional = false, QuantityType = quantityType, QuantityTypeId = quantityType.Id }; }