Пример #1
0
        //<div class="mdc-select">
        //    <i class="mdc-select__dropdown-icon"></i>
        //    <select class="mdc-select__native-control">
        //        <option value = "" disabled selected></option>
        //        <option value = "grains" >
        //            Bread, Cereal, Rice, and Pasta
        //        </option>
        //        <option value = "vegetables" >
        //            Vegetables
        //        </ option >
        //        < option value="fruit">
        //            Fruit
        //        </option>
        //    </select>
        //    <label class="mdc-floating-label">Pick a Food Group</label>
        //    <div class="mdc-line-ripple"></div>
        //</div>
        public static IHtmlContent GetMenuForWeb(string type, int menuID, int langID)
        {
            string keyCache = type + "_ChuyenMuc_" + langID;
            var    cache    = CacheExtends.GetDataFromCache <IHtmlContent>(keyCache);

            if (cache != null)
            {
                return(cache);
            }
            else
            {
                var    chuyenmuc = new CPMenuService();
                var    data      = chuyenmuc.GetItemByType(type, langID);
                string Html      = "<div class=\"mdc-select\"><i class=\"mdc-select__dropdown-icon\"></i><select name=\"MenuID\" class=\"mdc-select__native-control\"><option value=\"\">------ Chọn chuyên mục -----</option>";
                for (int i = 0; data != null && i < data.Count; i++)
                {
                    var item = data[i];
                    if (menuID > 0 && menuID == item.ID)
                    {
                        Html += "<option value =" + item.ID + " selected>" + item.Name + "</option>";
                    }
                    else
                    {
                        Html += "<option value =" + item.ID + ">" + item.Name + "</option>";
                    }
                }
                Html += "</select></div>";
                return(new HtmlString(Html));
            }
        }
Пример #2
0
        protected List <MenuControlAttribute> GetAdminContrller()
        {
            var cacheMenu = CacheExtends.GetDataFromCache <List <MenuControlAttribute> >(CacheExtends.DefaultAdminController);

            if (cacheMenu != null)
            {
                return(cacheMenu);
            }
            else
            {
                var cusMenus = new List <MenuControlAttribute>();
                var assembly = Assembly.GetAssembly(typeof(AdminController)).GetTypes()
                               .Where(o => o.BaseType.FullName == typeof(AdminController).FullName)
                               .ToList();
                int count = assembly != null ? assembly.Count : 0;
                for (int i = 0; i < count; i++)
                {
                    var item      = assembly[i];
                    var attribute = item.GetCustomAttribute <MenuControlAttribute>();
                    if (attribute == null)
                    {
                        continue;
                    }
                    var getmetho = item.GetMethods();
                    var method   = getmetho
                                   .Where(o => o.Module.Name == "MVCBase.dll")
                                   .Select(o => o.Name).ToList();
                    if (method != null)
                    {
                        foreach (var m in method)
                        {
                            attribute.ActionName.Add(m.ToLower());
                        }
                    }
                    cusMenus.Add(attribute);
                }
                CacheExtends.SetObjectFromCache(CacheExtends.DefaultAdminController, 360 * 24 * 60, cusMenus);

                return(cusMenus);
            }
        }
Пример #3
0
        /// <summary>
        /// Render html partialView with data from db
        /// </summary>
        /// <param name="partialView"></param
        /// <param name="ctrl"></param>
        /// <param name="properties"> key | value \r\n key | value \r\n  key | value</param>
        /// <returns></returns>

        public static IHtmlContent RenderWithData(this IHtmlHelper htmlHelper, string partialView, string ctrl, List <SysPropertyEntity> properties)
        {
            string keyCache = ctrl + "_partialView_" + partialView;
            var    cache    = CacheExtends.GetDataFromCache <IHtmlContent>(keyCache);

            if (cache == null)
            {
                var customer = properties;

                var data = GetDynamicDataByActName(ctrl, customer);
                var html = htmlHelper.PartialAsync(partialView, data);

                CacheExtends.SetObjectFromCache(keyCache, 10 * 60 * 24, html.Result);

                return(html.Result);
            }
            else
            {
                return(cache);
            }
        }
Пример #4
0
        private static void GetCurrentResource(this HttpContext context, ref List <CPResourceEntity> currentResource, ref CPLangEntity currentLang)
        {
            string cookie = context.GetValue(Cookies.DefaultLang, false);

            if (string.IsNullOrEmpty(cookie))
            {
                cookie = "vn";
            }
            var lang = new CPLangService();

            currentLang = lang.CreateQuery().SelectFirst(o => o.Activity == true && o.Code == cookie);
            // cache
            var cache = CacheExtends.GetDataFromCache <List <CPResourceEntity> >(cookie + "-" + CacheExtends.DefaultLang);

            //
            if (cache != null)
            {
                currentResource = cache;  return;
            }

            var res = new CPResourceService();

            currentResource = res.GetByLangID(currentLang.ID);
        }
Пример #5
0
        private static ClaimsPrincipal GetCurrentUser(this HttpContext context)
        {
            string token = context.GetValue(Cookies.DefaultLogin, false);

            if (string.IsNullOrEmpty(token))
            {
                return(null);
            }
            else
            {
                // neeus co cache
                var cache = CacheExtends.GetDataFromCache <ClaimsPrincipal>(token);
                if (cache != null)
                {
                    return(cache);
                }
                // ko co cache
                var    logs  = new CPLoginLogService();
                string email = logs.GetEmailFromDb(token);
                if (string.IsNullOrEmpty(email))
                {
                    return(null);
                }
                else
                {
                    var account = new CPUserService();
                    var user    = account.GetItemByEmail(email);
                    if (user == null)
                    {
                        return(null);
                    }
                    else
                    {
                        var role  = new CPRoleService();
                        var irole = role.GetItemByID(user.RoleID);
                        if (role == null)
                        {
                            return(null);
                        }
                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.Email, user.Email),
                            new Claim(ClaimTypes.Name, user.Name),
                            new Claim(ClaimTypes.Role, irole.Code),
                            new Claim("RoleID", irole.ID.ToString())
                        };
                        var claimsIdentity = new ClaimsIdentity(claims, Cookies.DefaultLogin);

                        var authenProperties = new AuthenticationProperties
                        {
                            IsPersistent = true,
                            ExpiresUtc   = DateTime.UtcNow.AddMinutes(Cookies.ExpiresLogin)
                        };
                        ClaimsPrincipal claim = new ClaimsPrincipal();
                        claim.AddIdentity(claimsIdentity);

                        CacheExtends.SetObjectFromCache(token, Cookies.ExpiresLogin, claim);

                        return(claim);
                    }
                }
            }
        }
Пример #6
0
        protected void GetClientContrller(ref List <MenuControlAttribute> cusMenus, ref List <CModule> modules)
        {
            var cacheControl = CacheExtends.GetDataFromCache <List <CModule> >(CacheExtends.DefaultIsControl);
            var cacheMenu    = CacheExtends.GetDataFromCache <List <MenuControlAttribute> >(CacheExtends.DefaultClientController);

            if (cacheMenu != null && cacheControl != null)
            {
                cusMenus = cacheMenu;
                modules  = cacheControl;
            }
            else
            {
                modules  = new List <CModule>();
                cusMenus = new List <MenuControlAttribute>();
                var assembly = Assembly.GetAssembly(typeof(ClientController)).GetTypes()
                               .Where(o => o.BaseType.FullName == typeof(ClientController).FullName)
                               .ToList();
                int count = assembly != null ? assembly.Count : 0;
                for (int i = 0; i < count; i++)
                {
                    var item      = assembly[i];
                    var attribute = item.GetCustomAttribute <MenuControlAttribute>();
                    if (attribute == null)
                    {
                        continue;
                    }
                    if (attribute.IsControl)
                    {
                        var fields = item.GetFields();
                        List <ProperyCModule> pp = new List <ProperyCModule>();
                        if (fields != null)
                        {
                            foreach (var field in fields)
                            {
                                var    attr = field.GetCustomAttribute <PropertyAttribute>();
                                string name = attr.Name;
                                string key  = field.Name;
                                string type = attr.Type;
                                pp.Add(new ProperyCModule(key, type, name));
                            }
                        }
                        modules.Add(new CModule()
                        {
                            Code       = attribute.CModule,
                            Name       = attribute.Name,
                            FullName   = item.FullName,
                            Properties = pp
                        });
                    }
                    else
                    {
                        var getmetho = item.GetMethods();
                        var method   = getmetho
                                       .Where(o => o.Module.Name == "MVCBase.dll")
                                       .Select(o => o.Name).ToList();
                        if (method != null)
                        {
                            foreach (var m in method)
                            {
                                attribute.ActionName.Add(m.ToLower());
                            }
                        }
                        cusMenus.Add(attribute);
                    }
                }
                CacheExtends.SetObjectFromCache(CacheExtends.DefaultIsControl, 360 * 24 * 60, modules);
                CacheExtends.SetObjectFromCache(CacheExtends.DefaultClientController, 360 * 24 * 60, cusMenus);
            }
        }