A property drawn from an Oda.Session class and automatically committed to the database
Ejemplo n.º 1
0
 /// <summary>
 /// Removes the specified _session property.
 /// </summary>
 /// <param name="sessionProperty">The _session property.</param>
 /// <returns></returns>
 public bool Remove(SessionProperty sessionProperty)
 {
     sessionProperty.SuspendUpdates = true;
     sessionProperty.AccountId = AccountId;
     sessionProperty.SessionId = SessionId;
     sessionProperty.Update();
     sessionProperty.SuspendUpdates = false;
     return Properties.Remove(sessionProperty);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the specified session property.
 /// </summary>
 /// <param name="sessionProperty">The _session property.</param>
 public void Add(SessionProperty sessionProperty)
 {
     sessionProperty.SuspendUpdates = true;
     sessionProperty.AccountId = AccountId;
     sessionProperty.SessionId = SessionId;
     sessionProperty.Update();
     sessionProperty.SuspendUpdates = false;
     Properties.Add(sessionProperty);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds the range.
 /// </summary>
 /// <param name="sessionProperties">The session properties.</param>
 public void AddRange(SessionProperty[] sessionProperties)
 {
     foreach(var sessionProperty in sessionProperties) {
         sessionProperty.SuspendUpdates = true;
         sessionProperty.AccountId = AccountId;
         sessionProperty.SessionId = SessionId;
         sessionProperty.Update();
         sessionProperty.SuspendUpdates = false;
         Properties.Add(sessionProperty);
     }
 }
Ejemplo n.º 4
0
 public Session Refresh(SqlConnection cn, SqlTransaction trans)
 {
     // fetch the most up to date info from the Sql server
     // Result 1
     // -> AccountId
     // Result 2
     // --> SessionPropertyId, Name, Value, DataType
     // @SessionId, @Referer, @UserAgent, @IpAddress, @AccountId
     var refreshCommand = AuthenticationPlugin.AuthenticationPluginRef.GetResourceString("/Sql/CreateUpdateSession.sql");
     using(var cmd = new SqlCommand(refreshCommand, cn)) {
         cmd.Parameters.Add("@SessionId", SqlDbType.UniqueIdentifier).Value = Id;
         var s = HttpContext.Current.Request.ServerVariables;
         var referer = s["HTTP_REFERER"];
         var userAgent = s["HTTP_USER_AGENT"];
         var ipAddress = s["REMOTE_ADDR"];
         if(referer == null) { referer = ""; }
         if(userAgent == null) { userAgent = ""; }
         if(ipAddress == null) { ipAddress = ""; }
         cmd.Parameters.Add("@Referer", SqlDbType.VarChar).Value = referer;
         cmd.Parameters.Add("@UserAgent", SqlDbType.VarChar).Value = userAgent;
         cmd.Parameters.Add("@IpAddress", SqlDbType.VarChar).Value = ipAddress;
         using(SqlDataReader r = cmd.ExecuteReader()) {
             r.Read();
             /* get AccountId */
             AccountId = r.GetGuid(0);
             /* get properties */
             r.NextResult();
             while(r.Read()) {
                 var p = new SessionProperty
                             {
                                 SuspendUpdates = true,
                                 SessionId = Id,
                                 AccountId = AccountId,
                                 Id = r.GetGuid(0),
                                 Name = r.GetString(1),
                                 Value = r.GetString(2),
                                 DataType = r.GetString(3)
                             };
                 Properties.Add(p);
                 p.SuspendUpdates = false;
             }
             /* get contacts */
             r.NextResult();
             while(r.Read()) {
                 var c = new Contact
                             {
                                 Id = r.GetGuid(0),
                                 AccountId = r.GetGuid(1),
                                 First = r.GetString(2),
                                 Middle = r.GetString(3),
                                 Last = r.GetString(4),
                                 Address = r.GetString(5),
                                 Address2 = r.GetString(6),
                                 City = r.GetString(7),
                                 State = r.GetString(8),
                                 Zip = r.GetString(9),
                                 Email = r.GetString(10),
                                 Company = r.GetString(11),
                                 Title = r.GetString(12),
                                 WebAddress = r.GetString(13),
                                 IMAddress = r.GetString(14),
                                 Fax = r.GetString(15),
                                 Home = r.GetString(16),
                                 Work = r.GetString(17),
                                 Mobile = r.GetString(18),
                                 Notes = r.GetString(19),
                                 Type = (ContactType) r.GetInt32(20)
                             };
                 if(c.Id == Id){
                     // if this contact id matches the
                     // account id, then this is the account's
                     // primary contact
                     Account.Contact = c;
                 }else{
                     if (Account.Contacts==null) Account.Contacts = new List<Contact>();
                     Account.Contacts.Add(c);
                 }
             }
         }
     }
     Properties.AccountId = AccountId;
     return this;
 }