Пример #1
0
        public IActionResult Create(mtOrders item)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname")))
            {
                return(RedirectToAction("index", "login"));
            }

            if (ModelState.IsValid)
            {
                string   user   = HttpContext.Session.GetString("fullname");
                DateTime txDate = DateTime.Now;

                item.createdBy = user;
                item.createdOn = txDate;
                item.updatedBy = user;
                item.updatedOn = txDate;

                mContext.mtOrders.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 == "Orders").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.Error = true;
            return(View("Create"));
        }
Пример #2
0
        public IActionResult IsActive(int id)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("fullname")))
            {
                return(RedirectToAction("index", "login"));
            }

            mtOrders item = mContext.mtOrders.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 = Microsoft.EntityFrameworkCore.EntityState.Modified;
            mContext.SaveChanges();

            return(RedirectToAction("Index"));
        }