public ActionResult Create([Bind(Include = "id,Product_id,FoodDay_id,weight,count,caloric,protein,carb,fat")] Product_FoodDay product_FoodDay)
        {
            if (ModelState.IsValid)
            {
                db.Product_FoodDay.Add(product_FoodDay);
                db.SaveChanges();
                FoodDay foodDay = db.FoodDay.Find(product_FoodDay.FoodDay_id);
                Product product = db.Product.Find(product_FoodDay.Product_id);

                product_FoodDay.caloric = product.caloric * (double)product_FoodDay.weight / (double)product.weight;
                product_FoodDay.carb    = product.carb * (double)product_FoodDay.weight / (double)product.weight;
                product_FoodDay.protein = product.protein * (double)product_FoodDay.weight / (double)product.weight;
                product_FoodDay.fat     = product.fat * (double)product_FoodDay.weight / (double)product.weight;
                product_FoodDay.caloric = product.caloric * (double)product_FoodDay.weight / (double)product.weight;

                foodDay.sumCarb        += product.carb * (double)product_FoodDay.weight / (double)product.weight;
                foodDay.sumProtein     += product.protein * (double)product_FoodDay.weight / (double)product.weight;
                foodDay.sumFat         += product.fat * (double)product_FoodDay.weight / (double)product.weight;
                foodDay.sumCaloric     += product.caloric * (double)product_FoodDay.weight / (double)product.weight;
                db.Entry(foodDay).State = EntityState.Modified;
                db.SaveChanges();



                return(RedirectToAction("Index"));
            }

            ViewBag.FoodDay_id = new SelectList(db.FoodDay, "id", "Users_id", product_FoodDay.FoodDay_id);
            ViewBag.Product_id = new SelectList(db.Product, "id", "Users_id", product_FoodDay.Product_id);
            return(View(product_FoodDay));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "id,Users_id,date,sumCaloric,sumProtein,sumCarb,sumFat,description")] FoodDay foodDay)
 {
     if (ModelState.IsValid)
     {
         db.Entry(foodDay).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Users_id = new SelectList(db.AspNetUsers, "Id", "Email", foodDay.Users_id);
     return(View(foodDay));
 }
Exemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            FoodDay foodDay = db.FoodDay.Find(id);

            if (foodDay.Product_FoodDay == null)
            {
                db.FoodDay.Remove(foodDay);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "id,Users_id,date,sumCaloric,sumProtein,sumCarb,sumFat,description")] FoodDay foodDay)
        {
            if (ModelState.IsValid)
            {
                foodDay.Users_id = User.Identity.GetUserId();
                db.FoodDay.Add(foodDay);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Users_id = new SelectList(db.AspNetUsers, "Id", "Email", foodDay.Users_id);
            return(View(foodDay));
        }
Exemplo n.º 5
0
        // GET: EveryoneFoodDays/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FoodDay foodDay = db.FoodDay.Find(id);

            if (foodDay == null)
            {
                return(HttpNotFound());
            }
            return(View(foodDay));
        }
Exemplo n.º 6
0
        public bool CreateFoodDayFromProfile(FoodDayCreateFromProfile model)
        {
            var entity =
                new FoodDay()
            {
                UserProfileId = model.UserProfileId,
                Date          = model.Date,
                CreatedBy     = _db.Users.Find(_userId).FirstName + " " + _db.Users.Find(_userId).LastName,
                CreatedUtc    = DateTimeOffset.Now
            };

            _db.FoodDays.Add(entity);
            return(_db.SaveChanges() == 1);
        }
Exemplo n.º 7
0
        // GET: FoodDays/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FoodDay foodDay = db.FoodDay.Find(id);

            if (foodDay == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Users_id = new SelectList(db.AspNetUsers, "Id", "Email", foodDay.Users_id);
            return(View(foodDay));
        }
        public ActionResult Details([Bind(Include = "id,weight")] Product chooseProduct)
        {
            var             idUser          = User.Identity.GetUserId();
            AspNetUsers     user            = db.AspNetUsers.Find(idUser);
            Product_FoodDay product_FoodDay = new Product_FoodDay();
            var             foodDay1        = db.FoodDay.Where(model => model.AspNetUsers.Id == idUser).ToList();
            var             id1             = foodDay1.Last().id;
            FoodDay         LastfoodDay     = db.FoodDay.Find(id1);
            Product         p1 = db.Product.Find(chooseProduct.id);

            product_FoodDay.weight     = chooseProduct.weight;
            product_FoodDay.Product_id = chooseProduct.id;
            product_FoodDay.FoodDay_id = LastfoodDay.id;
            chooseProduct.weight       = p1.weight;
            db.Product_FoodDay.Add(product_FoodDay);
            db.SaveChanges();

            FoodDay foodDay = db.FoodDay.Find(product_FoodDay.FoodDay_id);
            Product product = db.Product.Find(product_FoodDay.Product_id);

            /*if(product_FoodDay.weight == null)
             * {
             *  foodDay.sumCaloric = product.caloric * (double)product_FoodDay.count;
             *  foodDay.sumCarb += product.carb * (double)product_FoodDay.count;
             *  foodDay.sumProtein += product.protein * (double)product_FoodDay.count;
             *  foodDay.sumFat += product.fat * (double)product_FoodDay.count;
             *  db.Entry(foodDay).State = EntityState.Modified;
             *  db.SaveChanges();
             * }*/
            //else if(product_FoodDay.count == null)
            //{
            product_FoodDay.caloric = product.caloric * (double)product_FoodDay.weight / (double)product.weight;
            product_FoodDay.carb    = product.carb * (double)product_FoodDay.weight / (double)product.weight;
            product_FoodDay.protein = product.protein * (double)product_FoodDay.weight / (double)product.weight;
            product_FoodDay.fat     = product.fat * (double)product_FoodDay.weight / (double)product.weight;
            product_FoodDay.caloric = product.caloric * (double)product_FoodDay.weight / (double)product.weight;

            foodDay.sumCaloric += product.caloric * (double)product_FoodDay.weight / (double)product.weight;
            foodDay.sumCarb    += product.carb * (double)product_FoodDay.weight / (double)product.weight;
            foodDay.sumProtein += product.protein * (double)product_FoodDay.weight / (double)product.weight;
            foodDay.sumFat     += product.fat * (double)product_FoodDay.weight / (double)product.weight;
            if (user.caloricDemand != null)
            {
                if (foodDay.sumCaloric < (int)user.caloricDemand)
                {
                    foodDay.description = "Za mało spożyłeś kalorii";
                }
                else if (foodDay.sumCaloric > (int)user.caloricDemand)
                {
                    foodDay.description = "Spożyłeś za dużo kalorii";
                }
                else
                {
                    foodDay.description = "Spożyłeś odpowiednią ilość kalorii";
                }
            }

            db.Entry(foodDay).State = EntityState.Modified;
            db.SaveChanges();
            // }

            return(RedirectToAction("Index"));
        }