public ActionResult DeleteConfirmedPortionFood(int foodId, int dishId) { PortionFoodService.Remove(foodId, dishId); return(RedirectToAction("Edit", new RouteValueDictionary { { "id", dishId } })); }
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()); }
/// <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 DetailsPortionFood(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()); } return(View(portionFood)); }
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 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)); }
protected override void Seed(ApplicationDbContext context) { var type1 = new FoodConsistencyType { Name = "Твердый" }; var type2 = new FoodConsistencyType { Name = "Жидкий" }; var foodConsistencyTypeService = new FoodConsistencyTypeService(context); foodConsistencyTypeService.Add(type1); foodConsistencyTypeService.Add(type2); var fakeFoodCategory = new FoodCategory { DateModification = DateTime.Now, Name = "fake", Image = new byte[] { 3, 3 } }; var foodCategoryService = new FoodCategoryService(context); foodCategoryService.Add(fakeFoodCategory); var fakeDishCategory = new DishCategory { DateModification = DateTime.Now, Name = "fake", Image = new byte[] { 4 } }; var dishCategoryService = new DishCategoryService(context); dishCategoryService.Add(fakeDishCategory); var fakeDish1 = new Dish { Name = "fake1", DishCategory = fakeDishCategory, TotalAmountWater = 1, TotalCarbs = 1, TotalCcal = 1, TotalFat = 1, TotalProteins = 1, TotalSugar = 1 }; var fakeDish2 = new Dish { Name = "fake2", DishCategory = fakeDishCategory, TotalAmountWater = 2, TotalCarbs = 2, TotalCcal = 2, TotalFat = 2, TotalProteins = 2, TotalSugar = 2, IsDeleted = true }; var fakeDish3 = new Dish { Name = "fake3", DishCategory = fakeDishCategory, TotalAmountWater = 3, TotalCarbs = 3, TotalCcal = 3, TotalFat = 3, TotalProteins = 3, TotalSugar = 3 }; var fakeDish4 = new Dish { Name = "fake4", DishCategory = fakeDishCategory, TotalAmountWater = 4, TotalCarbs = 4, TotalCcal = 4, TotalFat = 4, TotalProteins = 4, TotalSugar = 4 }; var fakeDish5 = new Dish { Name = "fake5", DishCategory = fakeDishCategory, TotalAmountWater = 5, TotalCarbs = 5, TotalCcal = 5, TotalFat = 5, TotalProteins = 5, TotalSugar = 5 }; var dishService = new DishService(context); dishService.Add(fakeDish1); dishService.Add(fakeDish2); dishService.Add(fakeDish3); dishService.Add(fakeDish4); dishService.Add(fakeDish5); var fakeFood1 = new Food { Name = "fake1", FoodCategory = fakeFoodCategory, FoodConsistencyType = type1, Image = new byte[] { 1 }, AmountOfWater = 1, Carbs = 1, Ccal = 1, Fat = 1, Proteins = 1, Sugar = 1 }; var fakeFood2 = new Food { Name = "fake2", FoodCategory = fakeFoodCategory, FoodConsistencyType = type1, Image = new byte[] { 3 }, AmountOfWater = 2, Carbs = 2, Ccal = 2, Fat = 2, Proteins = 2, Sugar = 2 }; var foodService = new FoodService(context); foodService.Add(fakeFood1); foodService.Add(fakeFood2); var fakePortion1 = new PortionFood { Dish = fakeDish1, Food = fakeFood1, Amount = 3 }; var fakePortion2 = new PortionFood { Dish = fakeDish1, Food = fakeFood2, Amount = 5 }; var portionFoodService = new PortionFoodService(context); portionFoodService.Add(fakePortion1); portionFoodService.Add(fakePortion2); var fakeActivityType = new UserActivityType() { Description = "fake", Name = "fake" }; var fakeActivityTypeService = new UserActivityTypeService(context); fakeActivityTypeService.Add(fakeActivityType); RoleManager <IdentityRole> roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); ApplicationUserManager userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(context)); roleManager.Create(new IdentityRole("Admin")); roleManager.Create(new IdentityRole("User")); string adminEmail = "*****@*****.**"; if (userManager.Create(new ApplicationUser() { Email = adminEmail, UserName = "******" }, "bsuirhealthproject").Succeeded == true) { ApplicationUser user = userManager.FindByEmail(adminEmail); userManager.AddToRole(user.Id, "Admin"); userManager.AddToRole(user.Id, "User"); var userService = new UserService(context); userService.Add(new User { DateOfBirth = DateTime.Now, FirstName = "fake", IdActivityType = fakeActivityType.Id, IdUserCredential = user.Id, LastName = "fake", Sex = false }); } }