Exemplo n.º 1
0
        public ActionResult RefreshBusiness()
        {
            ReflectionController rc = new ReflectionController();
            List <ReflectionController.ReflectionResult> dsReflection = rc.GetControllerAndAction("HopDongMgr.Controllers");
            List <HT_DSChucNang> dsChucNang = db.HT_DSChucNang.ToList();

            for (int i = 0; i < dsReflection.Count; i++)
            {
                ReflectionController.ReflectionResult reflection = dsReflection[i];
                string tenController = reflection.Controller.Replace("Controller", "");
                string tenAction     = reflection.Action;
                string tenHienThi;
                if (!string.IsNullOrEmpty(reflection.Attributes))
                {
                    tenHienThi = tenController + "-" + tenAction + "-" + reflection.Attributes;
                }
                else
                {
                    tenHienThi = tenController + "-" + tenAction;
                }
                if (!tenHienThi.Contains("Home-") && !tenHienThi.Contains("Details") && reflection.Attributes.Contains("CustomAuthorization"))
                {
                    List <HT_DSChucNang> chucNangTonTai = dsChucNang.Where(a => a.TenController == tenController && a.TenAction == tenAction && a.TenHienThi == tenHienThi).ToList();
                    if (chucNangTonTai.Count == 0)
                    {
                        HT_DSChucNang chucNang = new HT_DSChucNang()
                        {
                            oid = Guid.NewGuid(), IsMenu = false, STT = i, TenController = tenController, TenAction = tenAction, TenHienThi = tenHienThi
                        };
                        db.HT_DSChucNang.Add(chucNang);
                    }
                }
            }
            db.SaveChanges();
            HT_LichSuHoatDong ls = new HT_LichSuHoatDong(
                this.ControllerContext.RouteData.Values["controller"].ToString()
                , "UPDATE"
                , DateTime.Now, Session["username"]?.ToString()
                , $" {this.ControllerContext.RouteData.Values["action"]?.ToString()} ");

            db.HT_LichSuHoatDong.Add(ls);
            db.SaveChanges();
            TempData["err"] = "<div class='alert alert-info' role='alert'><span class='glyphicon glyphicon-exclamation - sign' aria-hidden='true'></span><span class='sr - only'></span>Cập nhật thành công</div> ";
            return(RedirectToAction("Index"));
        }