public bool update(POCO.Food food) { if (food == null) { throw new ArgumentNullException(); } var entity = POCOObjToEntity(food); entity = _genericAccess.Update <Foods>(entity, food.Id); if (entity != null) { return(true); } return(false); }
public static POCO.Food EntityObjToPOCO(Foods entity) { if (entity == null) { return(null); } var food = new POCO.Food { Name = entity.Name, Category = entity.Category, Nutrition = entity.Nutrition }; return(food); }
public static Foods POCOObjToEntity(POCO.Food food) { if (food == null) { return(null); } var f = new Foods { Id = food.Id, Name = food.Name, Category = food.Category, Nutrition = food.Nutrition }; return(f); }
public IActionResult Update(POCO.Food food) { var service = new FoodService(_genericAccess, _foodAccess); JsonResult result; try { var ret = service.update(food); result = Json(ret); result.StatusCode = 200; } catch (Exception e) { result = Json(e); result.StatusCode = 400; } return(result); }
public POCO.Food create(POCO.Food food) { if (food == null) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(food.Name) || string.IsNullOrEmpty(food.Category)) { throw new ArgumentOutOfRangeException(); } var f = new Foods { Name = food.Name, Category = food.Category, Nutrition = food.Nutrition }; f = _genericAccess.Add(f); food.Id = f.Id; return(food); }