public ActionResult FoodAdd(Models.FoodAddModels models) { try { if (models.Food.ID != 0) { DB.Food food = db.Food.FirstOrDefault(x => x.ID == models.Food.ID); food.tr_Text = models.Food.tr_Text; food.en_Text = models.Food.en_Text; food.tr_Desc = models.Food.tr_Desc; food.en_Desc = models.Food.en_Desc; food.CategoryID = models.Food.CategoryID; food.Price = models.Food.Price; food.ModifiedDate = DateTime.Now; } else { models.Food.AddedDate = DateTime.Now; db.Food.Add(models.Food); } db.SaveChanges(); TempData["AddSucFood"] = "Başarılı Bir Şekilde Kaydedildi"; return(RedirectToAction("FoodAdd", "Panel")); } catch (Exception ex) { TempData["AddErrFood"] = ex.Message; return(View(models)); } }
public ActionResult FoodAdd(int?id) { if (Session["Login"] == null) { return(RedirectToAction("Login", "Panel")); } Models.FoodAddModels models = new Models.FoodAddModels(); if (id != null) { models.Food = db.Food.FirstOrDefault(x => x.ID == id); } models.list = db.Category.Where(x => x.CategroyID != null).Select(x => new SelectListItem() { Text = "(" + x.tr_Text + " - " + x.en_Text + ")", Value = x.ID.ToString() }).ToList(); return(View(models)); }