public static void GetUserDefaultAreaSetting(ref string areaId, ref string areaName) { HttpCookie areaCookie = HttpContext.Current.Request.Cookies.Get("udefaultarea"); if(areaCookie != null) { areaId = areaCookie.Values["Id"]; areaName = HttpUtility.UrlDecode(areaCookie.Values["Name"]); } else if (HttpContext.Current.User.Identity.IsAuthenticated) { ZsfEntities db = new ZsfEntities(); var defaultArea = db.V_UserDefaultArea.FirstOrDefault(r => r.UserName == HttpContext.Current.User.Identity.Name); if (defaultArea != null) { areaId = defaultArea.AreaId.ToString(); areaName = defaultArea.AreaValue; areaCookie = new HttpCookie("udefaultarea"); areaCookie.Domain = BaseDataModel.CookieDomain; areaCookie.Values["Id"] = areaId; areaCookie.Values["Name"] = HttpUtility.UrlEncode(areaName); areaCookie.Expires = DateTime.Now.AddYears(1); HttpContext.Current.Response.Cookies.Set(areaCookie); } } }
public static int GerUserUnreadMessagesCount() { if (!HttpContext.Current.User.Identity.IsAuthenticated) return 0; ZsfEntities db = new ZsfEntities(); return db.UserMessage.Where(r => r.UserInfo.Name == HttpContext.Current.User.Identity.Name && r.Readed == false).Count(); }