/// <summary>
        /// Get user using View: Account_Summary
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static AppUser AppUser_Get(int Id)
        {
            AppUser entity = new AppUser();

            using (var context = new ViewContext())
            {
                Views.Account_Summary item = context.Account_Summary.SingleOrDefault(s => s.Id == Id);

                if (item != null && item.Id > 0)
                {
                    MapFromDB(item, entity);
                }
            }

            return(entity);
        }
        //public static List<Views.AspNetUserRoles_Summary> GetUserRoles( int userId )
        //{
        //	using ( var context = new ViewContext() )
        //	{
        //		return context.AspNetUserRoles_Summary.Where( x => x.Id == userId ).ToList();
        //	}
        //}

        public static AppUser AppUser_GetByKey(string aspNetId)
        {
            AppUser entity = new AppUser();

            using (var context = new ViewContext())
            {
                Views.Account_Summary efEntity = context.Account_Summary
                                                 .SingleOrDefault(s => s.AspNetId == aspNetId);

                if (efEntity != null && efEntity.Id > 0)
                {
                    MapFromDB(efEntity, entity);
                }
            }

            return(entity);
        }
        public static AppUser GetUserByCEAccountId(string accountIdentifier)
        {
            AppUser entity = new AppUser();

            using (var context = new ViewContext())
            {
                Views.Account_Summary efEntity = context.Account_Summary
                                                 .FirstOrDefault(s => s.CEAccountIdentifier.ToLower() == accountIdentifier.ToLower());

                if (efEntity != null && efEntity.Id > 0)
                {
                    MapFromDB(efEntity, entity);
                }
            }

            return(entity);
        }
        public static AppUser GetUserByUserName(string username)
        {
            AppUser entity = new AppUser();

            using (var context = new ViewContext())
            {
                Views.Account_Summary efEntity = context.Account_Summary
                                                 .SingleOrDefault(s => s.UserName.ToLower() == username.ToLower());

                if (efEntity != null && efEntity.Id > 0)
                {
                    MapFromDB(efEntity, entity);
                }
            }

            return(entity);
        }
        public static AppUser AppUser_GetByEmail(string email)
        {
            AppUser entity = new AppUser();

            using (var context = new ViewContext())
            {
                Views.Account_Summary efEntity = context.Account_Summary
                                                 .FirstOrDefault(s => s.Email.ToLower() == email.ToLower());

                if (efEntity != null && efEntity.Id > 0)
                {
                    MapFromDB(efEntity, entity);
                }
            }

            return(entity);
        }
        //public void GetAllUsersInRole( string role )
        //{
        //	using ( var context = new EntityContext() )
        //	{
        //		var customers = context.AspNetUsers
        //			  .Where( u => u.AspNetUserRoles.Any( r => r..Name == role )  )
        //			  .ToList();
        //	}
        //}
        public static void MapFromDB(Views.Account_Summary fromEntity, AppUser to)
        {
            to.Id = fromEntity.Id;
            //to.RowId = fromEntity.RowId;
            to.UserName = fromEntity.UserName;

            to.AspNetUserId = fromEntity.AspNetId;
            //to.Password = fromEntity.Password;
            to.IsActive  = fromEntity.IsActive == null ? false : ( bool )fromEntity.IsActive;
            to.FirstName = fromEntity.FirstName;
            to.LastName  = fromEntity.LastName;
            to.SortName  = fromEntity.SortName;

            to.Email           = fromEntity.Email;
            to.Created         = fromEntity.Created;
            to.LastUpdated     = fromEntity.LastUpdated;
            to.LastUpdatedById = fromEntity.LastUpdatedById == null ? 0 : ( int )fromEntity.LastUpdatedById;
            if (IsValidDate(fromEntity.lastLogon))
            {
                to.lastLogon = (( DateTime )fromEntity.lastLogon).ToString("yyyy-MM-dd");
            }
            else
            {
                to.lastLogon = "None";
            }

            to.UserRoles = new List <string>();
            if (string.IsNullOrWhiteSpace(fromEntity.Roles) == false)
            {
                var roles = fromEntity.Roles.Split(',');
                foreach (string role in roles)
                {
                    to.UserRoles.Add(role);
                }
            }
        }         //