public ChallengeController(PrepContext context, UserManager <ApplicationUser> userManager, IHttpContextAccessor accessor)
        {
            var usr    = User ?? accessor.HttpContext.User;
            var userId = userManager.GetUserId(usr);

            _currentUser = context.Users.Find(userId);
            _context     = context;
            _context.Database.SetCommandTimeout(int.MaxValue);
        }
예제 #2
0
        public static void ImportTrivia(string fileName, PrepContext context)
        {
            DataSet ds = GetDatasetFromExcel(fileName);

            foreach (DataTable table in ds.Tables)
            {
                Score currentCatgory = (Score)Enum.Parse(typeof(Score), table.TableName.Trim());
                var   category       = new QuestionCategory
                {
                    CategoryName = table.TableName.Trim(),
                    ScoreWeight  = (int)currentCatgory
                };

                context.QuestionCategories.Add(category);
                context.SaveChanges();

                foreach (DataRow row in table.Rows)
                {
                    //3 columns of quesiton/answer pairs per sheet
                    var question_col1 = row[0].ToString();
                    var question_col2 = row[3].ToString();
                    var question_col3 = row[6].ToString();

                    var answer_col1 = row[1].ToString();
                    var answer_col2 = row[4].ToString();
                    var answer_col3 = row[7].ToString();

                    if (!string.IsNullOrEmpty(question_col1) && !string.IsNullOrEmpty(answer_col1))
                    {
                        var question1 = new Question
                        {
                            QuestionCategoryId = category.QuestionCategoryId,
                            QuestionBody       = question_col1,
                            Answer             = answer_col1.SanitizeAnswer()
                        };

                        context.Questions.Add(question1);
                    }

                    if (!string.IsNullOrEmpty(question_col2) && !string.IsNullOrEmpty(answer_col2))
                    {
                        var question2 = new Question
                        {
                            QuestionCategoryId = category.QuestionCategoryId,
                            QuestionBody       = question_col2,
                            Answer             = answer_col2.SanitizeAnswer()
                        };

                        context.Questions.Add(question2);
                    }

                    if (!string.IsNullOrEmpty(question_col3) && !string.IsNullOrEmpty(answer_col3))
                    {
                        var question3 = new Question
                        {
                            QuestionCategoryId = category.QuestionCategoryId,
                            QuestionBody       = question_col3,
                            Answer             = answer_col3.SanitizeAnswer()
                        };

                        context.Questions.Add(question3);
                    }
                }

                context.SaveChanges();
            }
        }
예제 #3
0
 public ShopController(PrepContext context, UserManager <ApplicationUser> userManager)
 {
     _context     = context;
     _userManager = userManager;
 }
예제 #4
0
 public UserController(PrepContext db, UserManager <ApplicationUser> userManager)
 {
     _db          = db;
     _userManager = userManager;
 }