public IActionResult Index() { if (err != null) { ViewBag.er = err; err = null; } //////////////////////////////////////////////////////////////////////////////////select list var qlist = db.tbl_category.Where(a => a.FatherIdCat == -1 || a.FatherIdCat == -2).ToList(); ViewBag.lselect = new SelectList(qlist, "Id", "NameCat"); ////////////////////////////////////////////////////////////////////////////list view bag complete var qlistt = db.tbl_category.ToList(); var tq = new List <Vm_Category>(); foreach (var item in qlistt) { if (item.FatherIdCat == -1) { NewFileName = "محصولات"; } else if (item.FatherIdCat == -2) { NewFileName = "اخبار و وبلاگ"; } else if (item.FatherIdCat == -3) { NewFileName = "صفحه اول"; } else { var namefather = qlistt.Where(a => a.Id == item.FatherIdCat).SingleOrDefault(); NewFileName = namefather.NameCat; } var d = new Vm_Category() { Id = item.Id, NameCat = item.NameCat, FatherIdCat = item.FatherIdCat, fathername = NewFileName }; tq.Add(d); } ViewBag.list = tq.OrderByDescending(a => a.Id).ToList(); ////////////////////////////////////////// return(View()); }
public IActionResult add(Vm_Category cat) { var qcat = db.tbl_category.Where(a => a.NameCat == cat.NameCat && a.FatherIdCat == cat.FatherIdCat).SingleOrDefault(); if (qcat != null) { err = "این نام قبلا ثبت شده است"; } else { var tbcat = new Tb_Category() { Language = cat.Language, NameCat = cat.NameCat, FatherIdCat = cat.FatherIdCat }; db.tbl_category.Add(tbcat); db.SaveChanges(); suc = "اطلاعات با موفقیت ثبت شد"; } return(RedirectToAction("index")); }