Hi folks,
I'm working on a custom module for our site. The process flow is as follows.
- Customer hits a specific page
- Page detects if customer is authenticated
- No - forces login/register
- Yes - Continues
- Verifies customer data
- Retrieves token and ttl from sister site
- Stores data in db table
- Redirects customer to sister site using token to login
I have the following class:
[TableName("PixfizzAutoRegister_Data")]
[PrimaryKey("rId", AutoIncrement = true)]
[Scope("ModuleId")]
[Cacheable("PixfizzAutoRegister_Data", CacheItemPriority.Normal, 20)]
public class PixFizzData
{
public int rId { get; set; }
public int UserID { get; set; }
public string Email { get; set; }
public string LastToken { get; set; }
public DateTime LastUpdate { get; set; }
}
Using the following code to update the database
using (IDataContext db = DataContext.Instance())
{
var repo = db.GetRepository<PixFizzData>();
var user = repo.Find($"WHERE UserID = {currentUser.UserID}");
db.BeginTransaction();
try
{
if (!user.Any())
{
repo.Insert(dataRecord);
db.Commit();
}
else
{
string query = string.Empty;
if (token != null)
{
query = $"SET [LastUpdateDate] = \'{DateTime.Now}\', [LastToken] = \'{token}\' WHERE [UserID] = {currentUser.UserID}";
}
repo.Update(query);
}
}
catch (Exception e)
{
db.RollbackTransaction();
Exceptions.ProcessModuleLoadException(this, ex);
}
}
The dataRecord is of the class PixFizzData.
I get an Object reference not set to an instance of an object error.
If I take the update out of a transaction block the table gets updated with correct data but the error still occurs.
Any guidance would be most appreciated.
~Scott