public ActionResult Scale(double gram = 100, bool type = false, string pronam = "") { ViewBag.username = username; ViewBag.ip = ip; string helper = weightresult(ip).Replace(".", ","); double helper2; if (type == false) { ViewBag.g = gram; } else { ViewBag.g = Convert.ToDouble(helper) * 10; } if (pronam == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product prod = db.Products.Find(pronam); if (prod == null) { ViewBag.existing = "This product is not in our database!"; return(View()); } if (status) { ViewBag.Protein = prod.Protein; ViewBag.Carbo = prod.Carb; ViewBag.Fats = prod.Fats; ProdHistory productt = new ProdHistory() { Name = prod.Name, Kcal = prod.Kcal * (ViewBag.g / 100), Protein = prod.Protein * (ViewBag.g / 100), Carb = prod.Carb * (ViewBag.g / 100), Fats = prod.Fats * (ViewBag.g / 100), Nick = username }; List <ProdHistory> help2 = dbh.ProdHistoryy.ToList(); productt.HisID = help2.Count; dbh.ProdHistoryy.Add(productt); dbh.SaveChanges(); } return(View(prod)); }
public ActionResult History(Object obj) { ViewBag.username = username; while (true) { try { ProdHistory item = dbh.ProdHistoryy.FirstOrDefault(x => x.Nick == username); dbh.ProdHistoryy.Remove(item); dbh.SaveChanges(); } catch { break; } } return(View()); }