Ejemplo n.º 1
0
        /// <summary>
        /// Use system user token to perform work
        /// </summary>
        /// <param name="token">Token returned from SuperId and validated</param>
        /// <returns>Contact entity created as the system user</returns>
        private static ContactEntity DoWorkAsSystemUser(SuperIdToken token)
        {
            // Enter database context for the customer (enter the right multi-tenant context)
            using (var context = SoDatabaseContext.EnterDatabaseContext(token.ContextIdentifier))
            {
                // set appropriate url for the customer tenant
                // ConfigFile.WebServices.RemoteBaseURL = token.NetserverUrl;

                // Log in as the system user
                using (var session = SoSession.Authenticate(new SoCredentials(token.Ticket)))
                {
                    // Do work as the system user
                    var principal = SoContext.CurrentPrincipal;
                    System.Diagnostics.Trace.WriteLine(principal.Associate);
                    using (var agent = new ContactAgent())
                    {
                        var timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                        var entity = agent.CreateDefaultContactEntity();
                        entity.Name = "SuperId-" + timestamp;
                        return(agent.SaveContactEntity(entity));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult CreateContactEntity()
        {
            using (var agent = new ContactAgent())
            {
                var timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                var entity = agent.CreateDefaultContactEntity();
                entity.Name = "SuperId-" + timestamp;
                var contact = agent.SaveContactEntity(entity);
                return(RedirectToAction("Index", new { id = contact.ContactId }));
            }
        }