public ActionResult Index() { var db = new GoodFit(); var users = db.Users; return(View(users)); }
public ActionResult ShowDish() { GoodFit db = new GoodFit(); var dish = db.Dish; return(View(dish)); }
//function help bool InDataBase(string email) { Users user = null; using (GoodFit db = new GoodFit()) { user = db.Users.FirstOrDefault(i => i.Email == email); } return((user == null) ? false : true); }
public static void UpdateDishAsync(this GoodFit bd, Dish newdish) { var dish = bd.Dish.FirstOrDefault(d => d.id == newdish.id); dish.Img = newdish.Img ?? dish.Img; dish.Name = newdish.Name; dish.Сalories = newdish.Сalories; dish.Contains_Meat = newdish.Contains_Meat; dish.Contains_Milk = newdish.Contains_Milk; dish.Contains_Sugar = newdish.Contains_Sugar; bd.SaveChanges(); }
public ActionResult AddDish(Dish dish, HttpPostedFileBase image1) { // if (ModelState.IsValid) { dish.Img = image1.ToByte(); db.Dish.Add(dish); try { db.SaveChanges(); } catch { db = new GoodFit(); } //} return(RedirectToAction("ShowDish")); }
// атрибуты Diet добавить при изминении update diet public static void UpdateDiet(this Diet newdiet, int[] arr) { using (var db = new GoodFit()) { Diet diet = db.Diet.FirstOrDefault(j => j.Id == newdiet.Id); diet.Name = newdiet.Name; diet.Subscription = newdiet.Subscription; diet.Description = newdiet.Description; if (arr.Length == 0) { db.Diet.FirstOrDefault(j => j.Id == newdiet.Id).Dish.Clear(); db.SaveChanges(); return; } foreach (var item in diet.Dish.ToList()) { if (arr.Contains(item.id)) { } else { db.Diet.FirstOrDefault(j => j.Id == newdiet.Id).Dish.Remove(db.Dish.FirstOrDefault(i => i.id == item.id)); } } db.SaveChanges(); diet.AddDishes(arr); db.SaveChanges(); } //db.Entry(diet).State = EntityState.Modified; //diet.Dish.Clear(); // db.Diet.FirstOrDefault(j => j.Id == diet.Id) }
public static void AddDishes(this Diet diet, int[] arr, bool save = true) { if (arr == null || arr.Length == 0) { throw new ArgumentException("Массив пустой"); } using (var db = new GoodFit()) { for (int i = 0; i < arr.Length; i++) { int Item_Id = arr[i]; Dish disht = db.Dish.FirstOrDefault(j => j.id == Item_Id) ?? throw new Exception(); db.Diet.FirstOrDefault(j => j.Id == diet.Id).Dish.Add(disht); //db.Dish.FirstOrDefault(j => j.id == Item_Id).Diet.Add(diet); } if (save) { db.SaveChanges(); } } }
public ActionResult Register(RegisterModel model, string Email) { if (ModelState.IsValid) { Users user = null; using (GoodFit db = new GoodFit()) { user = db.Users.FirstOrDefault(i => i.Name == model.Name); } if (user == null) { using (GoodFit db = new GoodFit()) { db.Users.Add(new Users() { Name = model.Name, Email = model.Email, Password = model.Password, Subscription = false }); try { db.SaveChanges(); } catch { ModelState.AddModelError("", "Error"); } user = db.Users.Where(i => i.Name == model.Name && i.Password == model.Password).FirstOrDefault(); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Error"); } } return(View(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { Users user = null; using (GoodFit db = new GoodFit()) { user = db.Users.FirstOrDefault(i => i.Name == model.Name && i.Password == model.Password); } if (user != null) { FormsAuthentication.SetAuthCookie(model.Name, true); return(RedirectToAction("Index", "User")); } else { //return RedirectToAction("Register", "Account"); ModelState.AddModelError("", "Error"); } } return(View(model)); }