internal UProfileData UserCookie(string cookie) { SessionsDbTable session; UsersDbTable curentUser; using (var db = new UserContext()) { session = db.Sessions.FirstOrDefault(s => s.CookieString == cookie && s.ExpireTime > DateTime.Now); } if (session == null) { return(null); } using (var db = new UserContext()) { var validate = new EmailAddressAttribute(); if (validate.IsValid(session.UserEmail)) { curentUser = db.Users.FirstOrDefault(u => u.Email == session.UserEmail); } else { curentUser = db.Users.FirstOrDefault(u => u.Email == session.UserEmail); } } if (curentUser == null) { return(null); } var userprofile = new UProfileData { Id = curentUser.Id, Name = curentUser.Name, Surname = curentUser.Surname, Email = curentUser.Email, Level = curentUser.Level }; return(userprofile); }
public static void SetMySessionObject(this HttpContext current, UProfileData profile) { current.Session.Add("__SessionObject", profile); }