/// <summary>
        /// Imports the user content from V2
        /// </summary>
        /// <param name="userStoriesTable">User Story data</param>
        /// <param name="userContentTable">User Content data</param>
        /// <param name="delimiter">Delimiter between data</param>
        /// <param name="work">The DB access</param>
        private void ImportAchievementUserStuff(
			HttpPostedFileBase userStoriesTable,
			HttpPostedFileBase userContentTable,
			String delimiter,
			UnitOfWork work)
        {
            // Grab the data
            List<Dictionary<String, String>> storyData = GetDataFromFile(userStoriesTable, delimiter);
            if (storyData == null)
            {
                ModelState.AddModelError("", "Error with User Story table.  Check Debug Output");
                return;
            }

            List<Dictionary<String, String>> contentData = GetDataFromFile(userContentTable, delimiter);
            if (contentData == null)
            {
                ModelState.AddModelError("", "Error with User Content table.  Check Debug Output");
                return;
            }

            // Go through stories
            try
            {
                work.EntityContext.Configuration.AutoDetectChangesEnabled = false;

                foreach (Dictionary<String, String> row in storyData)
                {
                    int oldID = int.Parse(row["userstoryID"]);
                    achievement_user_story story = new achievement_user_story()
                    {
                        date_submitted = DateTime.Parse(row["date_submitted"]),
                        image = row["uc_url"],
                        text = row["uc_text"]
                    };
                    ImportedEarnable impStory = new ImportedEarnable()
                    {
                        OldID = oldID,
                        UniqueData = row["date_submitted"]
                    };

                    work.EntityContext.achievement_user_story.Add(story);
                    _userStoryMap.Add(impStory.OldID, impStory);
                }
            }
            finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }

            // Save, then get new ids
            work.SaveChanges();
            foreach (ImportedEarnable impStory in _userStoryMap.Values)
            {
                DateTime submitTime = DateTime.Parse(impStory.UniqueData);
                impStory.NewID = (from s in work.EntityContext.achievement_user_story where s.date_submitted == submitTime select s.id).FirstOrDefault();
            }

            // Go through content
            try
            {
                work.EntityContext.Configuration.AutoDetectChangesEnabled = false;
                foreach (Dictionary<String, String> row in contentData)
                {
                    // Get the user
                    ImportedUser approver = GetImportedUserByOldID(row["approverID"]);
                    if (approver == null)
                        continue;

                    // Make the data entry
                    int oldID = int.Parse(row["usercontentID"]);
                    achievement_user_content content = new achievement_user_content()
                    {
                        submitted_date = DateTime.Parse(row["date_submitted"]),
                        text = row["uc_text"],
                        approved_by_id = approver.NewID,
                        approved_date = DateTime.Parse(row["date_handled"])
                    };

                    // content type
                    // 1 - image
                    // 2 - url
                    // 3 - text
                    int contentType = int.Parse(row["typeID"]);
                    switch (contentType)
                    {
                        case 1: // image
                            content.content_type = (int)JPPConstants.UserSubmissionTypes.Image;
                            content.image = row["uc_url"];
                            break;

                        case 2: // url
                            content.content_type = (int)JPPConstants.UserSubmissionTypes.URL;
                            content.url = row["uc_url"];
                            break;

                        case 3: // text
                            content.content_type = (int)JPPConstants.UserSubmissionTypes.Text;
                            break;
                    }

                    // Make the map item
                    ImportedEarnable impContent = new ImportedEarnable()
                    {
                        OldID = oldID,
                        UniqueData = row["date_submitted"]
                    };

                    work.EntityContext.achievement_user_content.Add(content);
                    _userContentMap.Add(impContent.OldID, impContent);
                }
            }
            finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }

            // Save, then get new ids
            work.SaveChanges();
            foreach (ImportedEarnable impStory in _userContentMap.Values)
            {
                DateTime submitTime = DateTime.Parse(impStory.UniqueData);
                impStory.NewID = (from s in work.EntityContext.achievement_user_content where s.submitted_date == submitTime select s.id).FirstOrDefault();
            }
        }
        /// <summary>
        /// Imports the quest templates from V2
        /// </summary>
        /// <param name="questTemplateTable">File w/ quest template data</param>
        /// <param name="questAchievementStepTable">Achievement steps data</param>
        /// <param name="delimiter">Delimiter between data</param>
        /// <param name="work">The DB access</param>
        private void ImportQuestTemplates(
			HttpPostedFileBase questTemplateTable,
			HttpPostedFileBase questAchievementStepTable,
			String delimiter,
			UnitOfWork work)
        {
            // Grab the data
            List<Dictionary<String, String>> questData = GetDataFromFile(questTemplateTable, delimiter);
            if (questData == null)
            {
                ModelState.AddModelError("", "Error with Quest Template table.  Check Debug Output");
                return;
            }

            List<Dictionary<String, String>> stepData = GetDataFromFile(questAchievementStepTable, delimiter);
            if (stepData == null)
            {
                ModelState.AddModelError("", "Error with Quest Step table.  Check Debug Output");
                return;
            }

            // Loop through quests
            try
            {
                work.EntityContext.Configuration.AutoDetectChangesEnabled = false;
                foreach (Dictionary<String, String> row in questData)
                {
                    // Get the creator
                    ImportedUser creator = GetImportedUserByOldID(row["creatorID"]);
                    if (creator == null || creator.NewID == 0)
                        continue;

                    ImportedUser modifiedBy = GetImportedUserByOldID(row["last_modified_by"]);
                    if (modifiedBy == null || modifiedBy.NewID == 0)
                        continue;

                    int oldID = int.Parse(row["questID"]);
                    int threshold = int.Parse(row["quest_threshhold"]);
                    quest_template quest = new quest_template()
                    {
                        created_date = DateTime.Parse(row["date_created"]),
                        creator_id = creator.NewID,
                        description = row["description"],
                        featured = Boolean.Parse(row["is_featured"]),
                        icon = row["icon"],
                        icon_file_name = "",
                        last_modified_by_id = modifiedBy.NewID,
                        last_modified_date = DateTime.Parse(row["date_modified"]),
                        posted_date = DateTime.Parse(row["date_posted"]),
                        retire_date = null,
                        state = (int)JPPConstants.AchievementQuestStates.Inactive,
                        threshold = threshold <= 0 ? (int?)null : threshold,
                        title = row["title"],
                        user_generated = false,
                        keywords = ""
                    };

                    ImportedEarnable impQuest = new ImportedEarnable()
                    {
                        OldID = oldID,
                        UniqueData = quest.title
                    };

                    work.EntityContext.quest_template.Add(quest);
                    _questMap.Add(impQuest.OldID, impQuest);
                }
            }
            finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }

            work.SaveChanges();

            foreach (ImportedEarnable impQuest in _questMap.Values)
            {
                impQuest.NewID = (from q in work.EntityContext.quest_template where q.title == impQuest.UniqueData select q.id).FirstOrDefault();
            }

            // Achievement steps
            try
            {
                work.EntityContext.Configuration.AutoDetectChangesEnabled = false;
                foreach (Dictionary<String, String> row in stepData)
                {
                    // Get the achievement and quest
                    ImportedEarnable quest = GetImportedEarnableByOldID(_questMap, row["questID"]);
                    if (quest == null || quest.NewID == 0)
                        continue;
                    ImportedEarnable achieve = GetImportedEarnableByOldID(_achievementMap, row["achievementID"]);
                    if (achieve == null || achieve.NewID == 0)
                        continue;

                    quest_achievement_step step = new quest_achievement_step()
                    {
                        achievement_id = achieve.NewID,
                        quest_id = quest.NewID
                    };

                    work.EntityContext.quest_achievement_step.Add(step);
                }
            }
            finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }
            work.SaveChanges();
        }
        /// <summary>
        /// Imports the achievements from V2
        /// </summary>
        /// <param name="achieveTemplateTable">File w/ achievement template data</param>
        /// <param name="achievePointTemplateTable">Achievement point template data (to be rolled into achievement)</param>
        /// <param name="achieveRequirementsTable">Achievement requirement data</param>
        /// <param name="achieveCaretakerTable">Achievement caretaker data</param>
        /// <param name="delimiter">Delimiter between data</param>
        /// <param name="work">The DB access</param>
        private void ImportAchievements(
			HttpPostedFileBase achieveTemplateTable,
			HttpPostedFileBase achievePointTemplateTable,
			HttpPostedFileBase achieveRequirementsTable,
			String delimiter,
			UnitOfWork work)
        {
            // Grab the data
            List<Dictionary<String, String>> achieveData = GetDataFromFile(achieveTemplateTable, delimiter);
            if (achieveData == null)
            {
                ModelState.AddModelError("", "Error with Achievement Template table.  Check Debug Output");
                return;
            }

            List<Dictionary<String, String>> pointData = GetDataFromFile(achievePointTemplateTable, delimiter);
            if (pointData == null)
            {
                ModelState.AddModelError("", "Error with Achievement Point Template table.  Check Debug Output");
                return;
            }

            List<Dictionary<String, String>> reqData = GetDataFromFile(achieveRequirementsTable, delimiter);
            if (reqData == null)
            {
                ModelState.AddModelError("", "Error with Achievement Requirements table.  Check Debug Output");
                return;
            }

            //List<Dictionary<String, String>> caretakerData = GetDataFromFile(achieveCaretakerTable, delimiter);
            //if (caretakerData == null)
            //{
            //	ModelState.AddModelError("", "Error with Achievement Caretaker table.  Check Debug Output");
            //	return;
            //}

            // The templates that need to be added
            List<achievement_template> templatesToAdd = new List<achievement_template>();

            // Go through each data row
            foreach (Dictionary<String, String> row in achieveData)
            {
                // Get related users
                ImportedUser editedBy = _userMap[int.Parse(row["last_modified_by"])];
                ImportedUser creator = _userMap[int.Parse(row["creatorID"])];
                if (creator == null)
                    continue; // Must have a creator

                // Grab other info
                int oldID = int.Parse(row["achievementID"]);

                int state = (int)JPPConstants.AchievementQuestStates.Active;
                bool isRetired = Boolean.Parse(row["is_retired"]);
                if (isRetired)
                    state = (int)JPPConstants.AchievementQuestStates.Retired;

                int type = (int)JPPConstants.AchievementTypes.Scan;
                switch (int.Parse(row["type"]))
                {
                    // 1 - usersubmission
                    case 1: type = (int)JPPConstants.AchievementTypes.UserSubmission; break;

                    // 2 - scan
                    case 2: type = (int)JPPConstants.AchievementTypes.Scan; break;

                    // 3 - system
                    case 3: type = (int)JPPConstants.AchievementTypes.System; break;

                    // 4 - adminassigned
                    case 4: type = (int)JPPConstants.AchievementTypes.AdminAssigned; break;

                    // 5 - threshold
                    case 5: type = (int)JPPConstants.AchievementTypes.Threshold; break;
                }

                int? triggerType = null;
                if (!String.IsNullOrWhiteSpace(row["system_trigger_type"]))
                {
                    switch (int.Parse(row["system_trigger_type"]))
                    {
                        // TODO: Finalize this
                        default: break;
                    }
                }

                // Set up the template
                achievement_template template = new achievement_template()
                {
                    id = oldID, // This will get overridden, but necessary for a look-up later
                    content_type = String.IsNullOrWhiteSpace(row["content_type"]) ? (int?)null : int.Parse(row["content_type"]),
                    created_date = DateTime.Parse(row["date_created"]),
                    creator_id = creator.NewID,
                    description = row["description"],
                    featured = Boolean.Parse(row["is_featured"]),
                    hidden = Boolean.Parse(row["is_hidden"]),
                    icon = row["icon"],
                    icon_file_name = "",
                    is_repeatable = Boolean.Parse(row["is_repeatable"]),
                    last_modified_by_id = editedBy == null ? (int?)null : editedBy.NewID,
                    modified_date = DateTime.Parse(row["date_modified"]),
                    parent_id = String.IsNullOrWhiteSpace(row["parentID"]) ? (int?)null : int.Parse(row["parentID"]),
                    posted_date = DateTime.Now,
                    repeat_delay_days = String.IsNullOrWhiteSpace(row["repeat_delay"]) ? (int?)null : int.Parse(row["repeat_delay"]),
                    retire_date = isRetired ? DateTime.Parse(row["date_retired"]) : (DateTime?)null,
                    state = state,
                    system_trigger_type = triggerType,
                    threshold = String.IsNullOrWhiteSpace(row["threshhold"]) ? (int?)null : int.Parse(row["threshhold"]),
                    title = row["title"],
                    type = type,
                    keywords = ""
                };

                // Create imported achievement
                ImportedEarnable impAchieve = new ImportedEarnable()
                {
                    UniqueData = template.title,
                    OldID = oldID
                };

                // Add to temporary list
                templatesToAdd.Add(template);
                _achievementMap.Add(impAchieve.OldID, impAchieve);
            }

            // Loop through points and put in correct achievements
            foreach (Dictionary<String, String> row in pointData)
            {
                int achievementID = int.Parse(row["achievementID"]);
                int categoryID = int.Parse(row["categoryID"]);
                int points = int.Parse(row["points"]);
                achievement_template template = templatesToAdd.Where(t => t.id == achievementID).FirstOrDefault();
                if (template == null)
                    continue;

                // Switch on old category id
                switch (categoryID)
                {
                    case 1: template.points_create = points; break;		// Create
                    case 2: template.points_learn = points; break;		// Learn
                    case 3: template.points_socialize = points; break;	// Socialize
                    case 4: template.points_explore = points; break;	// Explore
                }
            }

            // Add templates to database
            try
            {
                work.EntityContext.Configuration.AutoDetectChangesEnabled = false;
                foreach (achievement_template template in templatesToAdd)
                    work.EntityContext.achievement_template.Add(template);
            }
            finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }
            work.SaveChanges();

            // Update the map with new ids
            foreach (ImportedEarnable e in _achievementMap.Values)
            {
                e.NewID = (from a in work.EntityContext.achievement_template where a.title == e.UniqueData select a.id).FirstOrDefault();
            }

            // Put in requirements
            try
            {
                // Speed up
                work.EntityContext.Configuration.AutoDetectChangesEnabled = false;

                foreach (Dictionary<String, String> row in reqData)
                {
                    // Get this achievement
                    ImportedEarnable achieve = GetImportedEarnableByOldID(_achievementMap, row["achievementID"]);
                    if (achieve == null || achieve.NewID == 0)
                        continue;

                    work.EntityContext.achievement_requirement.Add(new achievement_requirement()
                    {
                        achievement_id = achieve.NewID,
                        description = row["description"]
                    });
                }
            }
            finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }
            work.SaveChanges();

            //// Put in caretakers
            //try
            //{
            //	// Speed up
            //	work.EntityContext.Configuration.AutoDetectChangesEnabled = false;

            //	foreach (Dictionary<String, String> row in caretakerData)
            //	{
            //		// Get this achievement and user
            //		ImportedEarnable achieve = GetImportedEarnableByOldID(_achievementMap, row["achievementID"]);
            //		if (achieve == null || achieve.NewID == 0)
            //			continue;
            //		ImportedUser user = GetImportedUserByOldID(row["caretakerID"]);
            //		if (user == null || user.NewID == 0)
            //			continue;

            //		work.EntityContext.achievement_caretaker.Add(new achievement_caretaker()
            //		{
            //			achievement_id = achieve.NewID,
            //			caretaker_id = user.NewID
            //		});
            //	}
            //}
            //finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; }
            //work.SaveChanges();
        }