New Posts New Posts RSS Feed: Server Side Entities
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Server Side Entities

 Post Reply Post Reply
Author
rickadams View Drop Down
Newbie
Newbie
Avatar

Joined: 04-Mar-2011
Posts: 12
Post Options Post Options   Quote rickadams Quote  Post ReplyReply Direct Link To This Post Topic: Server Side Entities
    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;
        }
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down