/// <summary>
        /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Web.Security.MembershipUser"/> object populated with the specified user's information from the data source.
        /// </returns>
        /// <param name="username">The name of the user to get information for. </param><param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user. </param>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            var cacheKey = string.Format("UserData_{0}", username);

            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return((CustomMembershipUser)HttpRuntime.Cache[cacheKey]);
            }

            using (var context = new MvcDemoEntities())
            {
                var user = (from u in context.Users.Include(usr => usr.UserRole)
                            where String.Compare(u.Username, username, StringComparison.OrdinalIgnoreCase) == 0

                            select u).FirstOrDefault();

                if (user == null)
                {
                    return(null);
                }

                var membershipUser = new CustomMembershipUser(user);

                //Store in cache
                HttpRuntime.Cache.Insert(cacheKey, membershipUser, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);

                return(membershipUser);
            }
        }
Esempio n. 2
0
        //public ActionResult Hot()
        //{
        //    return View(MvcApplication.CurrentEntities.Blogs.OrderByDescending(x => x.Hit).First());
        //}

        public ActionResult Part()
        {
            using (var entites = new MvcDemoEntities())
            {
                return(View(entites.Blogs.OrderByDescending(x => x.CreateOn).Take(5).ToArray()));
            }
        }
Esempio n. 3
0
 public ActionResult Hot()
 {
     using (var entites = new MvcDemoEntities())
     {
         return(View(entites.Blogs.OrderByDescending(x => x.Hit).First()));
     }
 }
 /// <summary>
 /// Get the list of contact reasons
 /// </summary>
 /// <param name="getFromCache"></param>
 /// <returns></returns>
 public static List <UserRole> GetUserRoles(bool getFromCache)
 {
     return((List <UserRole>)GetFromCache("UserRoles", getFromCache, delegate
     {
         using (var context = new MvcDemoEntities())
         {
             return context.UserRoles.OrderBy(ur => ur.UserRoleName).ToList();
         }
     }));
 }
 /// <summary>
 /// Get the list of contact reasons
 /// </summary>
 /// <param name="getFromCache"></param>
 /// <returns></returns>
 public static List <ContactReason> GetContactReasons(bool getFromCache)
 {
     return((List <ContactReason>)GetFromCache("ContactReasons", getFromCache, delegate
     {
         using (var context = new MvcDemoEntities())
         {
             return context.ContactReasons.OrderBy(c => c.ContactReasonText).ToList();
         }
     }));
 }
        /// <summary>
        /// Verifies that the specified user name and password exist in the data source.
        /// </summary>
        /// <returns>
        /// true if the specified username and password are valid; otherwise, false.
        /// </returns>
        /// <param name="username">The name of the user to validate. </param><param name="password">The password for the specified user. </param>
        public override bool ValidateUser(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            using (var context = new MvcDemoEntities())
            {
                var user = (from u in context.Users
                            where String.Compare(u.Username, username, StringComparison.OrdinalIgnoreCase) == 0 &&
                            String.Compare(u.Password, password, StringComparison.OrdinalIgnoreCase) == 0

                            select u).FirstOrDefault();

                return(user != null);
            }
        }
        public List <UIEmployee> GetEmployee()
        {
            MvcDemoEntities   entities    = new MvcDemoEntities();
            List <UIEmployee> lstEmployee = new List <UIEmployee>();

            lstEmployee = (from e in entities.Employees.Where(o => o.StatusTypeId == 1)
                           select new UIEmployee
            {
                EmployeeId = e.EmployeeId,
                FirstName = e.FirstName,
                GenderId = e.GenderId,
                CountryId = e.CountryId,
                StateId = e.StateId,
                LastName = e.LastName,
                MobileNo = e.MobileNo,
                EmailId = e.EmailId,
                ZipCode = e.ZipCode,
                Address = e.Address
            }
                           ).ToList();
            return(lstEmployee);
        }
        /// <summary>
        /// Gets a list of the roles that a specified user is in for the configured applicationName.
        /// </summary>
        /// <returns>
        /// A string array containing the names of all the roles that the specified user is in for the configured applicationName.
        /// </returns>
        /// <param name="username">The user to return a list of roles for.</param>
        public override string[] GetRolesForUser(string username)
        {
            //Return if the user is not authenticated
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            //Return if present in Cache
            var cacheKey = string.Format("UserRoles_{0}", username);

            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return((string[])HttpRuntime.Cache[cacheKey]);
            }

            //Get the roles from DB
            var userRoles = new string[] { };

            using (var context = new MvcDemoEntities())
            {
                var user = (from u in context.Users.Include(usr => usr.UserRole)
                            where String.Compare(u.Username, username, StringComparison.OrdinalIgnoreCase) == 0
                            select u).FirstOrDefault();

                if (user != null)
                {
                    userRoles = new[] { user.UserRole.UserRoleName }
                }
                ;
            }

            //Store in cache
            HttpRuntime.Cache.Insert(cacheKey, userRoles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);

            // Return
            return(userRoles.ToArray());
        }