public dynamic LeerCelularParametro(string sesion)
 {
     if (!String.IsNullOrEmpty(sesion))
     {
         return(CacheFunction.LeerByte(cache.Get(sesion + "-NumeroCelular")));
     }
     return(string.Empty);
 }
 public static T CachedValue <U, T>(this Dictionary <U, T> dict, U key, CacheFunction <U, T> f)
 {
     if (dict.ContainsKey(key))
     {
         return(dict[key]);
     }
     return(dict[key] = f(key));
 }
예제 #3
0
        public IActionResult Logout(string userid)
        {
            HttpContext.Session.Remove(SessionConfig.Kz_UserSession);
            HttpContext.Response.Cookies.Delete(CookieConfig.Kz_UserCookie);

            CacheFunction.Clear(this.HttpContext, string.Format(CacheConfig.Kz_User_MenuFunctionCache_Key, userid, SecurityModel.Cache_Key));

            return(RedirectToAction("Index", "Login"));
        }
 public void GuardarNombreLider(string sesion, string NombreLider)
 {
     if (!String.IsNullOrEmpty(sesion) && !String.IsNullOrEmpty(NombreLider))
     {
         cache.Remove(sesion + "-NombreLider");
         cache.Set(sesion + "-NombreLider", CacheFunction.GuardarByte(NombreLider));
         _bussinessRepository.GuardarMensajesPantallaExito(sesion, true);
     }
 }
        public string LeerNumeroLider(string sesion)
        {
            string numeroLider = string.Empty;

            if (!String.IsNullOrEmpty(sesion))
            {
                numeroLider = CacheFunction.LeerByte(cache.Get(sesion + "-NumeroLider"));
            }
            return(numeroLider);
        }
        public dynamic LeerMensajesPantallaExito()
        {
            JObject ObjTitulo    = JsonConvert.DeserializeObject <JObject>(CacheFunction.LeerByte(cache.Get("exito-TituloError")));
            JObject ObjSubTitulo = JsonConvert.DeserializeObject <JObject>(CacheFunction.LeerByte(cache.Get("exito-SubTituloError")));
            string  origen       = CacheFunction.LeerByte(cache.Get("exito-Origen"));

            return(new JObject
            {
                { "TituloError", ObjTitulo["Mensaje"].ToString() },
                { "SubTituloError", ObjSubTitulo["Mensaje"].ToString() },
                { "Origen", origen }
            });
        }
 public dynamic ResumenComunidad(string sesion)
 {
     if (!String.IsNullOrEmpty(sesion))
     {
         if (!cacheM.TryGetValue <JObject>(sesion + "-ResumenComunidad", out JObject valorRetorno))
         {
             valorRetorno = _bussinessRepository.ResumenComunidad(sesion);
             cacheM.Set(sesion + "-ResumenComunidad", CacheFunction.GuardarByte(valorRetorno.ToString()));
         }
         return(valorRetorno);
     }
     return(string.Empty);
 }
 public void GuardarDatosIntegrante(string sesion, string NombreIntegrante, string CelularIntegrante, double CapacidadAsignada)
 {
     if (!String.IsNullOrEmpty(sesion) && !String.IsNullOrEmpty(NombreIntegrante) && !String.IsNullOrEmpty(CelularIntegrante) && Double.TryParse(CapacidadAsignada.ToString(), out double price))
     {
         cache.Remove(sesion + "-DatosIntegrante-NombreIntegrante");
         cache.Set(sesion + "-DatosIntegrante-NombreIntegrante", CacheFunction.GuardarByte(NombreIntegrante));
         cache.Remove(sesion + "-DatosIntegrante-CelularIntegrante");
         cache.Set(sesion + "-DatosIntegrante-CelularIntegrante", CacheFunction.GuardarByte(CelularIntegrante));
         cache.Remove(sesion + "-DatosIntegrante-CapacidadAsignda");
         cache.Set(sesion + "-DatosIntegrante-CapacidadAsignda", CacheFunction.GuardarByte(CapacidadAsignada.ToString()));
         _bussinessRepository.GuardarMensajesPantallaExito(sesion, false);
     }
 }
        public static Font FontStyleCache(Font baseFont, FontStyle style, float height)
        {
            FontStyleCacheKey key = new FontStyleCacheKey(style, baseFont, height);
            CacheFunction <FontStyleCacheKey, Font> cache = x =>
            {
                Font f = baseFont;
                if (x.height != CachedHeight(f))
                {
                    f = new Font(f.FontFamily, x.height);
                }
                if (x.style != f.Style)
                {
                    f = new Font(f, x.style);
                }
                return(f);
            };

            return(fontStyleCache.CachedValue(key, cache));
        }
        public dynamic LeerDatosIntegrante(string sesion)
        {
            if (!String.IsNullOrEmpty(sesion))
            {
                string NombreIntegrante  = CacheFunction.LeerByte(cache.Get(sesion + "-DatosIntegrante-NombreIntegrante"));
                string CelularIntegrante = CacheFunction.LeerByte(cache.Get(sesion + "-DatosIntegrante-CelularIntegrante"));

                string primerNombreIntegrante = NombreIntegrante.IndexOf(" ") > -1
                ? NombreIntegrante.Substring(0, NombreIntegrante.IndexOf(" "))
                : NombreIntegrante;


                return(new JObject
                {
                    { "nombre", primerNombreIntegrante },
                    { "celular", CelularIntegrante }
                });
            }
            return(null);
        }
        public dynamic InformacionPantallaError(string sesion)
        {
            if (!String.IsNullOrEmpty(sesion))
            {
                JObject ObjTitulo    = JsonConvert.DeserializeObject <JObject>(CacheFunction.LeerByte(cache.Get(sesion + "-TituloError")));
                JObject ObjSubTitulo = JsonConvert.DeserializeObject <JObject>(CacheFunction.LeerByte(cache.Get(sesion + "-SubTituloError")));

                string titulo;
                try { titulo = ObjTitulo["Mensaje"].ToString(); } catch { throw; };
                string subtitulo;
                try { subtitulo = ObjSubTitulo["Mensaje"].ToString(); } catch { throw; };
                string origen;
                try { origen = CacheFunction.LeerByte(cache.Get(sesion + "-Origen")); } catch { throw; };

                return(new JObject
                {
                    { "TituloError", titulo },
                    { "SubTituloError", subtitulo },
                    { "Origen", origen }
                });
            }
            return(string.Empty);
        }
예제 #12
0
        public static Task <List <SY_MenuFunction> > MenuFunctionByUserId(SessionModel user, HttpContext context)
        {
            var connecttype = AppSettingHelper.GetStringFromFileJson("connectstring", "ConnectionStrings:DefaultType").Result;

            //
            var identify = string.Format(CacheConfig.Kz_User_MenuFunctionCache_Key, user.UserId, SecurityModel.Cache_Key);

            var modelCache = new List <SY_MenuFunction>();

            //var cache = context.RequestServices.GetService<IMemoryCache>();

            var existed = CacheFunction.TryGet <List <SY_MenuFunction> >(context, identify, out modelCache);

            //var k = cache.Get<List<SY_MenuFunction>>(identify);

            if (existed == false)
            {
                if (user.isAdmin)
                {
                    //Làm việc với mông => không thể dùng cmd giống như sqlserve, mysql
                    switch (connecttype)
                    {
                    case DatabaseModel.MONGO:

                        var filter = Builders <SY_MenuFunction> .Filter.Eq(n => n.Active, true);

                        var kd = MongoHelper.GetConnect <SY_MenuFunction>().FindAsync(filter);

                        modelCache = kd.Result.ToList();

                        break;

                    default:

                        var cmdMenus = "SELECT * FROM sy_menufunction WHERE Active = 1";

                        modelCache = Kztek_Library.Helpers.DatabaseHelper.ExcuteCommandToList <SY_MenuFunction>(cmdMenus);

                        break;
                    }
                }
                else
                {
                    switch (connecttype)
                    {
                    case DatabaseModel.MONGO:

                        var filterRole = Builders <SY_Map_User_Role> .Filter.Eq(n => n.UserId, user.UserId);

                        var moRoles = MongoHelper.GetConnect <SY_Map_User_Role>().FindAsync(filterRole).Result.ToList();

                        var filterMenu = Builders <SY_Map_Role_Menu> .Filter.In(n => n.RoleId, moRoles.Select(n => n.RoleId));

                        var moMenus = MongoHelper.GetConnect <SY_Map_Role_Menu>().FindAsync(filterMenu).Result.ToList();

                        var filterQueryMenu = Builders <SY_MenuFunction> .Filter.In(n => n.Id, moMenus.Select(n => n.MenuId));

                        modelCache = MongoHelper.GetConnect <SY_MenuFunction>().FindAsync(filterQueryMenu).Result.ToList();

                        break;

                    default:

                        var cmdRole = string.Format("SELECT * FROM sy_map_user_role WHERE UserId = '{0}'", user.UserId);

                        var roles = Kztek_Library.Helpers.DatabaseHelper.ExcuteCommandToList <SY_Map_User_Role>(cmdRole);

                        var str_roles = new List <string>();
                        foreach (var item in roles)
                        {
                            str_roles.Add(string.Format("'{0}'", item.RoleId));
                        }

                        //Danh sách menu của tài khoản với roleids = > danh sách menu
                        var cmdRoleMenus = string.Format("SELECT * FROM sy_map_role_menu WHERE RoleId IN ({0})", roles.Any() ? string.Join(",", str_roles) : "'0'");

                        var rolemenus = Kztek_Library.Helpers.DatabaseHelper.ExcuteCommandToList <SY_Map_Role_Menu>(cmdRoleMenus);

                        //Lấy danh sách menu quyền
                        var menuids = "";
                        var count1  = 0;
                        foreach (var item in rolemenus)
                        {
                            count1++;
                            menuids += string.Format("'{0}'{1}", item.MenuId, count1 == rolemenus.Count ? "" : ",");
                        }

                        var cmdMenus = string.Format("SELECT * FROM sy_menufunction WHERE Active = 1 AND Id IN ({0})", string.IsNullOrWhiteSpace(menuids) ? "'0'" : menuids);

                        modelCache = Kztek_Library.Helpers.DatabaseHelper.ExcuteCommandToList <SY_MenuFunction>(cmdMenus);

                        break;
                    }
                }

                //Save lại vào cache
                if (modelCache == null)
                {
                    modelCache = new List <SY_MenuFunction>();
                }

                CacheFunction.Add <List <SY_MenuFunction> >(context, identify, modelCache, CacheConfig.Kz_User_MenuFunctionCache_Time);
                //cache.Set<List<SY_MenuFunction>>(identify, modelCache, DateTime.Now.AddHours(8));
            }

            return(Task.FromResult(modelCache));
        }