Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesIRepository Insert Member Throwing ExceptionIRepository Insert Member Throwing Exception
Previous
 
Next
New Post
2/3/2016 9:56 AM
 

Hi folks,

I'm working on a custom module for our site. The process flow is as follows.

  1. Customer hits a specific page
  2. Page detects if customer is authenticated
    1. No - forces login/register
    2. Yes - Continues
  3. Verifies customer data
  4. Retrieves token and ttl from sister site
  5. Stores data in db table
  6. 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 { getset; }
        public int UserID { getset; }
        public string Email { getset; }
        public string LastToken { getset; }
        public DateTime LastUpdate { getset; }
    }

 

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(thisex);
                    }
 
                }

 

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

 

 
New Post
2/4/2016 4:54 PM
 
Did you step though it with the debugger?

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesIRepository Insert Member Throwing ExceptionIRepository Insert Member Throwing Exception


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  


Copyright 2017 by DNN Corp Terms of Use Privacy
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out