public IActionResult Create(mtChartOfAccount item) { string user = HttpContext.Session.GetString("fullname"); DateTime txDate = DateTime.Now; item.createdBy = user; item.createdOn = txDate; item.updatedBy = user; item.updatedOn = txDate; item.parentId = (item.parentId == 0 ? null : item.parentId); if (ModelState.IsValid) { mContext.mtChartOfAccount.Add(item); mContext.SaveChanges(); return(RedirectToAction("Index")); } if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } ICollection <sysModule> moduleLvl1 = mContext.sysModuleRole.Include(x => x.module) .Where(x => x.userRoleId == HttpContext.Session.GetInt32("roleId") && x.isActive == true && x.module.level == 1) .Select(x => x.module).ToList(); ICollection <sysModule> moduleLvl2 = mContext.sysModuleRole.Include(x => x.module) .Where(x => x.userRoleId == HttpContext.Session.GetInt32("roleId") && x.isActive == true && x.module.level == 2) .Select(x => x.module).ToList(); ViewBag.moduleLvl1 = moduleLvl1.OrderBy(x => x.orderModule); ViewBag.moduleLvl2 = moduleLvl2.OrderBy(x => x.orderModule); ViewBag.user = HttpContext.Session.GetString("fullname"); try { sysModule menu2 = moduleLvl2.Where(x => x.code == "ChartOfAccount").SingleOrDefault(); sysModule menu1 = moduleLvl1.Where(x => x.id == menu2.parentId).SingleOrDefault(); ViewData["Menu"] = menu1.name; ViewData["SubMenuLvl1"] = menu2.name; ViewData["Title"] = menu2.name; } catch { return(RedirectToAction("index", "login")); } ViewBag.Currency = mContext.mtCurrency.Where(x => x.isActive == true).ToList(); ViewBag.ChartOfAccount = mContext.mtChartOfAccount.Where(x => x.isActive == true).ToList(); ViewBag.Error = true; return(View("Create")); }
public IActionResult IsActive(int id) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname"))) { return(RedirectToAction("index", "login")); } mtChartOfAccount item = mContext.mtChartOfAccount.Find(id); item.isActive = !item.isActive; string user = HttpContext.Session.GetString("fullname"); DateTime txDate = DateTime.Now; item.updatedBy = user; item.updatedOn = txDate; mContext.Entry(item).State = EntityState.Modified; mContext.SaveChanges(); return(RedirectToAction("Index")); }