Print Page | Close Window

Server Side Entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2715
Printed Date: 01-Sep-2025 at 3:53pm


Topic: Server Side Entities
Posted By: rickadams
Subject: Server Side Entities
Date Posted: 25-May-2011 at 7:50am
I am looking for the correct way to perform server-side code without using a remote procedure type mechanism. I wish to use a SessionID as part of my login component. I have implemented a LoginManager and have been using the Login method to successfully authenticate my user and return the IPrincipal object. Now I wish to as part of the server side login code to generate a SessionID ( I know there is a DevForce SessionKey ), insert time and date of the session and associated UserAccountID into the database and return the autogenerated SessionID as a property in the Principal object. I have enclosed some sample code. I am assuming my problem here is that the SaveChanges in the new_Session method is ASync. If it is server side can I make it synchronous or how do I complete the login process in this context.
 
       /// <summary>
        ///
        /// </summary>
        /// <param name="credential"></param>
        /// <param name="entityManager"></param>
        /// <returns></returns>
        public IPrincipal Login(ILoginCredential credential, EntityManager entityManager)
        {
            UserConfigEntities userEntities = new UserConfigEntities(entityManager);
            if (credential == null)
            {
                throw new LoginException(LoginExceptionType.NoCredentials, "No credentials supplied");
            }
            // Return an IPrincipal. Any serializable type may be returned,  
            // here we use the DevForce UserIdentity and UserBase classes.  
            UserAccount aUser = Get_User(userEntities, credential.UserName);
            Verify_Credentials(aUser, credential.UserName, credential.Password, credential.Domain);
            var identity = new LEAF.Security.LEAFIdentity(credential.UserName, credential.Domain);
            var principal = new LEAF.Security.LEAFUser(identity, null);
            principal.loggedInUser = aUser;
            principal.SessionId = new_Session(entityManager, aUser);
            return principal;
        }
 
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private Int32 new_Session(EntityManager entityManager, UserAccount aUser)
        {
            LEAFSession userSession = new LEAFSession();
            userSession.UserAccountID = aUser.UserAccountID;
            DateTime currentDateTime = DateTime.Now;
            userSession.DT_SessionStart = currentDateTime;
            //update the datetime and sessionID for the Session
            userSession.DT_Insert = currentDateTime;
            userSession.DT_Update = currentDateTime;
            userSession.SID_Insert = -1;
            userSession.SID_Update = -1;
            entityManager.AddEntity(userSession);
            entityManager.SaveChanges();
            return userSession.LEAF_SessionID;
        }



Replies:
Posted By: sbelini
Date Posted: 26-May-2011 at 5:21pm
Hi rickadams,
 
SaveChanges is actually synchronous.
Is your userSession entity being saved at all?
In case it's not being saved, what's the reason? (you can check the SaveResult) Have you implemented a SaveInterceptor?
 
Silvio.



Print Page | Close Window