/// <summary> /// Post example /// </summary> /// <param name="startDateDecorator"></param> public SynchronizationData Post(DateTimeDecorator startDateDecorator) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Input data format is invalid."); return(null); } DateTime startDate = startDateDecorator.DateTime; var data = new SynchronizationData(); context = Request.GetOwinContext().Get <ApplicationDbContext>(); foodConsistencyTypeService = new FoodConsistencyTypeService(context); data.FoodConsistencyTypes = foodConsistencyTypeService.Get(startDate).ToList(); foodCategoryService = new FoodCategoryService(context); data.FoodCategories = foodCategoryService.Get(startDate).ToList(); dishCategoryService = new DishCategoryService(context); data.DishCategories = dishCategoryService.Get(startDate).ToList(); foodService = new FoodService(context); data.Food = foodService.Get(startDate).ToList(); dishService = new DishService(context); data.Dishes = dishService.Get(startDate).ToList(); portionService = new PortionFoodService(context); data.Portions = portionService.Get(startDate).ToList(); return(data); }
public ActionResult AddPortionFood([Bind(Include = "IdFood, Amount")] PortionFood portion) { int idDish = int.Parse(RouteData.Values["Id"].ToString()); if (ModelState.IsValid) { portion.IdDish = idDish; ValidationResult result = PortionFoodService.Add(portion); if (!result.IsSuccess) { var errorDetails = result.GetAllErrors(); throw new HttpException(404, "Model you add is incorrect. " + errorDetails); } } List <int> usedInDishFoodIds = DishService.Get(idDish).PortionFood. Where(p => !p.IsDeleted).Select(pf => pf.Food.Id).ToList(); ViewBag.IdFood = new SelectList( FoodService.Get().Where(x => !usedInDishFoodIds.Contains(x.Id)), "Id", "Name"); ViewBag.IdDish = idDish; return(View()); }
static void Main(string[] args) { DishService ds = new DishService(); Console.WriteLine(ds.Get(2)); Console.ReadKey(); }
public ActionResult Details(int id) { DishService dishService = new DishService(); Dish dish = dishService.Get(id); DishDetailsModel model = dish.Map <DishDetailsModel>(); return(View(model)); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Dish dishToDel = DishService.Get((int)id); return(View(dishToDel)); }
public ActionResult Search(string name) { var model = DishService.Get() .Where(e => e.User.FirstName.Contains(name) || e.User.LastName.Contains(name) || e.User.UserCredential.UserName.Contains(name) || e.Id.ToString() == name || e.DishCategory.Name.Contains(name) || e.Name.Contains(name)).ToList(); return(View("Index", model)); }
public ActionResult AddPortionFood(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } List <int> usedInDishFoodIds = DishService.Get(id.Value).PortionFood. Where(p => !p.IsDeleted).Select(pf => pf.Food.Id).ToList(); ViewBag.IdFood = new SelectList( FoodService.Get().Where(x => !usedInDishFoodIds.Contains(x.Id)), "Id", "Name"); ViewBag.IdDish = id; PortionFood portion = new PortionFood(); return(View(portion)); }
public ActionResult EditPortionFood([Bind(Include = "IdFood,IdDish,Amount")] PortionFood portionFood) { if (ModelState.IsValid) { PortionFoodService.Update(portionFood.IdFood, portionFood.IdDish, portionFood); return(RedirectToAction("Edit", new RouteValueDictionary { { "id", portionFood.IdDish } })); } List <int> usedInDishFoodIds = DishService.Get(portionFood.IdDish).PortionFood. Where(p => !p.IsDeleted).Select(pf => pf.Food.Id).ToList(); ViewBag.IdFood = new SelectList( FoodService.Get().Where(x => !usedInDishFoodIds.Contains(x.Id)), "Id", "Name"); ViewBag.IdDish = portionFood.IdDish; return(View(portionFood)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Dish dish = DishService.Get(id.Value); //List<String> strings = new List<String>(); SelectList list = new SelectList(DishCategoryService.Get(), "Id", "Name"); list.First(i => { // strings.Add(i.Text); return(i.Value == dish.IdDishCategory.ToString()); }).Selected = true; ViewBag.IdDishCategory = list; ViewBag.DishToView = dish; return(View(dish.PortionFood)); }
public ActionResult EditPortionFood(int?foodId, int?dishId) { if (foodId == null || dishId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PortionFood portionFood = PortionFoodService.Get(foodId.Value, dishId.Value); if (portionFood == null) { return(HttpNotFound()); } List <int> usedInDishFoodIds = DishService.Get(dishId.Value).PortionFood. Where(p => !p.IsDeleted).Select(pf => pf.Food.Id).ToList(); ViewBag.IdFood = new SelectList( FoodService.Get().Where(f => !usedInDishFoodIds.Contains(f.Id) || f.Id == foodId.Value), "Id", "Name"); ViewBag.IdDish = dishId.Value; return(View(portionFood)); }
public ActionResult Index() { Model = DishService.Get().ToList(); return(View(Model)); }
public async Task <ActionResult <IEnumerable <Dish> > > Get() { return(await _dishService.Get()); }
public Item Get(int id) { return(_dishService.Get(id)); }