/// <summary>
        /// Creates a new quest_template and adds it to the database
        /// </summary>
        /// <param name="model">The AddQuestViewModel passed in from the controller</param>
        public void AddQuest(AddQuestViewModel model)
        {
            quest_template newQuest = new quest_template
            {
                created_date        = DateTime.Now,
                creator_id          = model.CreatorID,
                description         = model.Description,
                featured            = false,
                icon                = model.IconFilePath,
                icon_file_name      = model.Icon,
                last_modified_by_id = null,
                last_modified_date  = null,
                posted_date         = null,
                retire_date         = null,
                state               = (int)JPPConstants.AchievementQuestStates.Draft,
                threshold           = model.Threshold,
                title               = model.Title,
                user_generated      = model.UserGenerated,
                keywords            = "",
            };

            List <quest_achievement_step> questAchievementSteps = new List <quest_achievement_step>();

            foreach (int i in model.SelectedAchievementsList)
            {
                quest_achievement_step q = new quest_achievement_step
                {
                    achievement_id = i,
                    quest_id       = newQuest.id
                };
                questAchievementSteps.Add(q);
            }

            AddQuestTemplateToDatabase(newQuest);
            AddAchievementStepsToDatabase(questAchievementSteps);

            Save();
        }
        /// <summary>
        /// Creates a new quest_template and adds it to the database
        /// </summary>
        /// <param name="model">The AddQuestViewModel passed in from the controller</param>
        public void AddQuest(AddQuestViewModel model)
        {
            quest_template newQuest = new quest_template
            {
                created_date = DateTime.Now,
                creator_id = model.CreatorID,
                description = model.Description,
                featured = false,
                icon = model.IconFilePath,
                icon_file_name = model.Icon,
                last_modified_by_id = null,
                last_modified_date = null,
                posted_date = null,
                retire_date = null,
                state = (int)JPPConstants.AchievementQuestStates.Draft,
                threshold = model.Threshold,
                title = model.Title,
                user_generated = model.UserGenerated,
                keywords = "",
            };

            List<quest_achievement_step> questAchievementSteps = new List<quest_achievement_step>();
            foreach (int i in model.SelectedAchievementsList)
            {
                quest_achievement_step q = new quest_achievement_step
                {
                    achievement_id = i,
                    quest_id = newQuest.id
                };
                questAchievementSteps.Add(q);
            }

            AddQuestTemplateToDatabase(newQuest);
            AddAchievementStepsToDatabase(questAchievementSteps);

            Save();
        }
        /// <summary>
        /// Gets the specified quest_template and updates it with any edits
        /// </summary>
        /// <param name="id">The id of the quest_template</param>
        /// <param name="model">The EditQuestViewModel passed in from the controller</param>
        public void AdminEditQuest(int id, EditQuestViewModel model)
        {
            List<LoggerModel> logChanges = new List<LoggerModel>();
            quest_template currentQuest = _dbContext.quest_template.Find(id);

            if (currentQuest == null)
                return;

            #region// Title
            if (currentQuest.title != model.Title && !String.IsNullOrWhiteSpace(model.Title))
            {
                logChanges.Add(new LoggerModel()
                {
                    Action = "Edit Quest: " + Logger.EditQuestLogType.Title.ToString(),
                    UserID = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1 = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1 = id,
                    Value1 = currentQuest.title,
                    Value2 = model.Title
                });
                currentQuest.title = model.Title;
            }
            #endregion

            #region// Description
            if (currentQuest.description != model.Description && !String.IsNullOrWhiteSpace(model.Description))
            {
                logChanges.Add(new LoggerModel()
                {
                    Action = "Edit Quest: " + Logger.EditQuestLogType.Description.ToString(),
                    UserID = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1 = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1 = id,
                    Value1 = currentQuest.description,
                    Value2 = model.Description
                });
                currentQuest.description = model.Description;
            }
            #endregion

            #region// Icon
            if (currentQuest.icon != model.IconFilePath && !String.IsNullOrWhiteSpace(model.IconFilePath))
            {
                logChanges.Add(new LoggerModel()
                {
                    Action = "Edit Quest: " + Logger.EditQuestLogType.Icon.ToString(),
                    UserID = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1 = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1 = id,
                    Value1 = currentQuest.icon,
                    Value2 = model.IconFilePath
                });
                currentQuest.icon = model.IconFilePath;
                currentQuest.icon_file_name = model.Icon;
            }
            #endregion

            #region// Posted Date
            if (currentQuest.state != model.State && model.State.Equals((int)JPPConstants.AchievementQuestStates.Active) && currentQuest.posted_date == null)
                currentQuest.posted_date = DateTime.Now;
            #endregion

            #region// Retire Date
            if (currentQuest.state != model.State && model.State.Equals((int)JPPConstants.AchievementQuestStates.Retired) && currentQuest.retire_date == null)
                currentQuest.retire_date = DateTime.Now;
            if (currentQuest.state != model.State && currentQuest.state.Equals((int)JPPConstants.AchievementQuestStates.Retired))
                currentQuest.retire_date = null;
            #endregion

            #region// State
            if (currentQuest.state != model.State)
            {
                logChanges.Add(new LoggerModel()
                {
                    Action = "Edit Quest: " + Logger.EditQuestLogType.State.ToString(),
                    UserID = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1 = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1 = id,
                    Value1 = currentQuest.state.ToString(),
                    Value2 = model.State.ToString()
                });
                currentQuest.state = model.State;
            }
            #endregion

            #region//Featured
            if (currentQuest.state != (int)JPPConstants.AchievementQuestStates.Active)
                currentQuest.featured = false;
            #endregion

            #region// Last Modified By And Date Last Modified
            currentQuest.last_modified_by_id = model.EditorID;
            currentQuest.last_modified_date = DateTime.Now;
            #endregion

            #region// Threshold
            if (currentQuest.threshold != model.Threshold)
            {
                logChanges.Add(new LoggerModel()
                {
                    Action = "Edit Quest: " + Logger.EditQuestLogType.Threshold.ToString(),
                    UserID = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1 = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1 = id,
                    Value1 = currentQuest.threshold.ToString(),
                    Value2 = model.Threshold.ToString()
                });
                currentQuest.threshold = model.Threshold;
            }
            #endregion

            #region// Replace achievement steps
            IEnumerable<quest_achievement_step> oldQuestAchievementSteps = _dbContext.quest_achievement_step.Where(q => q.quest_id == id);
            foreach (quest_achievement_step step in oldQuestAchievementSteps)
                _dbContext.quest_achievement_step.Remove(step);

            List<quest_achievement_step> newQuestAchievementSteps = new List<quest_achievement_step>();
            foreach (int i in model.SelectedAchievementsList)
            {
                quest_achievement_step q = new quest_achievement_step
                {
                    achievement_id = i,
                    quest_id = id
                };
                newQuestAchievementSteps.Add(q);
            }

            AddAchievementStepsToDatabase(newQuestAchievementSteps);

            #endregion

            if (logChanges.Count > 0)
                Logger.LogMultipleEntries(logChanges, _dbContext);

            Save();

            CheckAllUserQuestCompletion(currentQuest.id);
        }
        /// <summary>
        /// Gets the specified quest_template and updates it with any edits
        /// </summary>
        /// <param name="id">The id of the quest_template</param>
        /// <param name="model">The EditQuestViewModel passed in from the controller</param>
        public void AdminEditQuest(int id, EditQuestViewModel model)
        {
            List <LoggerModel> logChanges   = new List <LoggerModel>();
            quest_template     currentQuest = _dbContext.quest_template.Find(id);

            if (currentQuest == null)
            {
                return;
            }

            #region// Title
            if (currentQuest.title != model.Title && !String.IsNullOrWhiteSpace(model.Title))
            {
                logChanges.Add(new LoggerModel()
                {
                    Action    = "Edit Quest: " + Logger.EditQuestLogType.Title.ToString(),
                    UserID    = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1   = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1       = id,
                    Value1    = currentQuest.title,
                    Value2    = model.Title
                });
                currentQuest.title = model.Title;
            }
            #endregion

            #region// Description
            if (currentQuest.description != model.Description && !String.IsNullOrWhiteSpace(model.Description))
            {
                logChanges.Add(new LoggerModel()
                {
                    Action    = "Edit Quest: " + Logger.EditQuestLogType.Description.ToString(),
                    UserID    = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1   = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1       = id,
                    Value1    = currentQuest.description,
                    Value2    = model.Description
                });
                currentQuest.description = model.Description;
            }
            #endregion

            #region// Icon
            if (currentQuest.icon != model.IconFilePath && !String.IsNullOrWhiteSpace(model.IconFilePath))
            {
                logChanges.Add(new LoggerModel()
                {
                    Action    = "Edit Quest: " + Logger.EditQuestLogType.Icon.ToString(),
                    UserID    = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1   = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1       = id,
                    Value1    = currentQuest.icon,
                    Value2    = model.IconFilePath
                });
                currentQuest.icon           = model.IconFilePath;
                currentQuest.icon_file_name = model.Icon;
            }
            #endregion

            #region// Posted Date
            if (currentQuest.state != model.State && model.State.Equals((int)JPPConstants.AchievementQuestStates.Active) && currentQuest.posted_date == null)
            {
                currentQuest.posted_date = DateTime.Now;
            }
            #endregion

            #region// Retire Date
            if (currentQuest.state != model.State && model.State.Equals((int)JPPConstants.AchievementQuestStates.Retired) && currentQuest.retire_date == null)
            {
                currentQuest.retire_date = DateTime.Now;
            }
            if (currentQuest.state != model.State && currentQuest.state.Equals((int)JPPConstants.AchievementQuestStates.Retired))
            {
                currentQuest.retire_date = null;
            }
            #endregion

            #region// State
            if (currentQuest.state != model.State)
            {
                logChanges.Add(new LoggerModel()
                {
                    Action    = "Edit Quest: " + Logger.EditQuestLogType.State.ToString(),
                    UserID    = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1   = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1       = id,
                    Value1    = currentQuest.state.ToString(),
                    Value2    = model.State.ToString()
                });
                currentQuest.state = model.State;
            }
            #endregion

            #region//Featured
            if (currentQuest.state != (int)JPPConstants.AchievementQuestStates.Active)
            {
                currentQuest.featured = false;
            }
            #endregion

            #region// Last Modified By And Date Last Modified
            currentQuest.last_modified_by_id = model.EditorID;
            currentQuest.last_modified_date  = DateTime.Now;
            #endregion

            #region// Threshold
            if (currentQuest.threshold != model.Threshold)
            {
                logChanges.Add(new LoggerModel()
                {
                    Action    = "Edit Quest: " + Logger.EditQuestLogType.Threshold.ToString(),
                    UserID    = model.EditorID,
                    IPAddress = HttpContext.Current.Request.UserHostAddress,
                    TimeStamp = DateTime.Now,
                    IDType1   = Logger.LogIDType.QuestTemplate.ToString(),
                    ID1       = id,
                    Value1    = currentQuest.threshold.ToString(),
                    Value2    = model.Threshold.ToString()
                });
                currentQuest.threshold = model.Threshold;
            }
            #endregion

            #region// Replace achievement steps
            IEnumerable <quest_achievement_step> oldQuestAchievementSteps = _dbContext.quest_achievement_step.Where(q => q.quest_id == id);
            foreach (quest_achievement_step step in oldQuestAchievementSteps)
            {
                _dbContext.quest_achievement_step.Remove(step);
            }

            List <quest_achievement_step> newQuestAchievementSteps = new List <quest_achievement_step>();
            foreach (int i in model.SelectedAchievementsList)
            {
                quest_achievement_step q = new quest_achievement_step
                {
                    achievement_id = i,
                    quest_id       = id
                };
                newQuestAchievementSteps.Add(q);
            }

            AddAchievementStepsToDatabase(newQuestAchievementSteps);

            #endregion

            if (logChanges.Count > 0)
            {
                Logger.LogMultipleEntries(logChanges, _dbContext);
            }

            Save();

            CheckAllUserQuestCompletion(currentQuest.id);
        }