Exemple #1
0
        public TestController(Helper helper)
        {
            this._helper = helper;
            this._db     = new ProductHouseContext();

            Tuple <int, int> ids = Helper.GetLanguagesId();

            NativeLanguageId   = ids.Item1;
            LearningLanguageId = ids.Item2;
        }
Exemple #2
0
 public void SaveTestResult([FromBody] TestResults testResult)
 {
     if (testResult != null)
     {
         testResult.TestDate = DateTime.Now;
         using (ProductHouseContext db = new ProductHouseContext())
         {
             db.TestResults.Add(testResult);
             db.SaveChanges();
         }
     }
 }
 public TestResults GetById(int id)
 {
     using (ProductHouseContext db = new ProductHouseContext())
     {
         try
         {
             return(db.TestResults.First(c => c.Id == id));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Exemple #4
0
 public Users GetById(int id)
 {
     using (ProductHouseContext db = new ProductHouseContext())
     {
         try
         {
             return(db.Users.FirstOrDefault());
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Exemple #5
0
 public LanguageTranslations GetById(int id)
 {
     using (ProductHouseContext db = new ProductHouseContext())
     {
         try
         {
             return(db.LanguageTranslations.FirstOrDefault(c => c.Id == id));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
 public TotalScores GetById(int id)
 {
     using (ProductHouseContext db = new ProductHouseContext())
     {
         try
         {
             return(db.TotalScores.Where(c => c.Id == id).FirstOrDefault());
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
 public CategoriesTranslations GetById(int id)
 {
     using (ProductHouseContext db = new ProductHouseContext())
     {
         try
         {
             return(db.CategoriesTranslations.First(c => c.Id == id));
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Exemple #8
0
        private List <CategoryStatistic> FillCategory()
        {
            List <CategoryStatistic> categoryStatistic = new List <CategoryStatistic>();
            ProductHouseContext      db = new ProductHouseContext();

            var CategoryTranslations = (from categoryTrans in db.CategoriesTranslations
                                        join category in db.Categories on categoryTrans.CategoryId equals category.Id
                                        where categoryTrans.LangId == _userLanguageId
                                        select new
            {
                CategoryTrans = categoryTrans.Translation,
                CategoryId = category.Id,
                ParentId = category.ParentId
            }).ToList();

            var testsTrans = (from testTrans in db.TestTranslations
                              where testTrans.LangId == _userLanguageId
                              join test in db.Tests on testTrans.TestId equals test.Id
                              select new
            {
                TestTrans = testTrans.Translation,
                TestId = test.Id
            }).ToList();

            var parentCategories = CategoryTranslations.Where(c => c.ParentId == null).ToArray();

            for (int i = 0; i < parentCategories.Count(); i++)
            {
                var parentCategory = parentCategories[i];
                categoryStatistic.Add(new CategoryStatistic
                {
                    CategoryName = parentCategory.CategoryTrans
                });

                List <SubcategoryStatistic> subcategoryStatistics = new List <SubcategoryStatistic>();
                foreach (var subcategory in CategoryTranslations.Where(s => s.ParentId == parentCategory.CategoryId))
                {
                    subcategoryStatistics.Add(new SubcategoryStatistic
                    {
                        SubcategoryName = subcategory.CategoryTrans,
                        TestNames       = testsTrans.Select(t => t.TestTrans).ToList(),
                        CategoryId      = subcategory.CategoryId
                    });
                }

                categoryStatistic[i].SubcategoryStatistics = subcategoryStatistics;
            }

            return(categoryStatistic);
        }
        public IActionResult Register([FromBody] Users user)
        {
            if (user == null)
            {
                return(InvalidClientRequest());
            }

            LoginModel loginModel = new LoginModel
            {
                Login    = user.Email,
                Password = user.PasswordHash
            };

            string       userId         = Guid.NewGuid().ToString("N");
            string       hashedPassword = _helper.ComputeSha256Hash(user.PasswordHash);
            UserSettings userSettings   = new UserSettings
            {
                LearningLanguageId = 0,
                NativeLanguageId   = 0,
                UserId             = userId
            };

            user.Id           = userId;
            user.UserSettings = new List <UserSettings> {
                userSettings
            };
            user.PasswordHash = hashedPassword;

            using (ProductHouseContext db = new ProductHouseContext())
            {
                db.Users.Add(user);
                db.SaveChanges();
            }


            return(Login(loginModel));
        }
 public TestsResultsRepository()
 {
     db = new ProductHouseContext(ConfigurateOptions.GetOptions());
 }
Exemple #11
0
 public LanguagesTranslationsRepository()
 {
     db = new ProductHouseContext(ConfigurateOptions.GetOptions());
 }
Exemple #12
0
 public TotalScoresRepository()
 {
     db = new ProductHouseContext(ConfigurateOptions.GetOptions());
 }
Exemple #13
0
 public Helper(IHttpContextAccessor httpContextAccessor)
 {
     _db = new ProductHouseContext();
     _httpContextAccessor = httpContextAccessor;
 }
 public CategoriesRepository()
 {
     db = new ProductHouseContext(ConfigurateOptions.GetOptions());
 }