Esempio n. 1
0
 public CourseWordSuiteModel Map(WordSuite wordSuite)
 {
     return new CourseWordSuiteModel()
     {
         Id = wordSuite.Id,
         Name = wordSuite.Name
     };
 }
Esempio n. 2
0
 public int Add(WordSuite wordSuite)
 {
     using (var context = new WorldOfWordsDatabaseContext())
     {
         context.WordSuites.AddOrUpdate(wordSuite);
         context.SaveChanges();
         return wordSuite.Id;
     }
 }
 public TrainingWordSuiteModel Map(WordSuite WordSuite)
 {
     TrainingWordSuiteModel wordSuiteModel = new TrainingWordSuiteModel();
     wordSuiteModel.Id = WordSuite.Id;
     wordSuiteModel.OwnerId = WordSuite.OwnerId;
     wordSuiteModel.QuizResponseTime = WordSuite.QuizResponseTime;
     wordSuiteModel.QuizStartTime = WordSuite.QuizStartTime;
     wordSuiteModel.Name = WordSuite.Name;
     wordSuiteModel.WordTranslations = new List<WordTranslationModel>();
     wordSuiteModel.WordTranslations.AddRange(WordSuite.WordProgresses.Select(x => _mapper.Map(x.WordTranslation)).ToList());
     return wordSuiteModel;
 }
Esempio n. 4
0
 public int Add(WordSuite wordSuite)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         uow.WordSuiteRepository.AddOrUpdate(wordSuite);
         uow.Save();
         return wordSuite.Id;
     }
     //using (var context = new WorldOfWordsDatabaseContext())
     //{
     //    context.WordSuites.AddOrUpdate(wordSuite);
     //    context.SaveChanges();
     //    return wordSuite.Id;
     //}
 }
Esempio n. 5
0
 public WordSuiteEditModel MapForEdit(WordSuite wordSuite)
 {
     if (wordSuite == null)
     {
         throw new ArgumentNullException("wordSuite");
     }
     return new WordSuiteEditModel()
     {
         Id = wordSuite.Id,
         Name = wordSuite.Name,
         Language = wordSuite.Language.Name,
         LanguageId = wordSuite.LanguageId,
         Threshold = wordSuite.Threshold,
         QuizResponseTime = wordSuite.QuizResponseTime
     };
 }
        public TrainingWordSuiteModel Map(WordSuite WordSuite)
        {
            TrainingWordSuiteModel wordSuiteModel = new TrainingWordSuiteModel();
            wordSuiteModel.Id = WordSuite.Id;
            wordSuiteModel.OwnerId = WordSuite.OwnerId;
            wordSuiteModel.QuizResponseTime = WordSuite.QuizResponseTime;
            wordSuiteModel.QuizStartTime = WordSuite.QuizStartTime;
            wordSuiteModel.Name = WordSuite.Name;
            wordSuiteModel.LanguageId = WordSuite.LanguageId;
            wordSuiteModel.Threshold = WordSuite.Threshold;
            wordSuiteModel.WordTranslations = new List<WordTranslationModel>();
            wordSuiteModel.WordTranslations.AddRange(WordSuite.WordProgresses.Select(x => _mapper.Map(x.WordTranslation)).ToList());
            for (int i = 0; i < wordSuiteModel.WordTranslations.Count; i++)
            {
                wordSuiteModel.WordTranslations[i].Progress = (int)(WordSuite.WordProgresses.ToList())[i].Progress;

            }
            return wordSuiteModel;
        }
        public void Map_WordSuiteAndCourseWordSuiteModelAreEqual()
        {
            //Arrange
            var initial = new WordSuite
            {
                Id = 1,
                Name = "Day of week"
            };
            var expected = new CourseWordSuiteModel
            {
                Id = 1,
                Name = "Day of week"
            };
            //Act
            var actual = (new WordSuiteMapper()).Map(initial);

            //Assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Name, actual.Name);
        }
Esempio n. 8
0
        public bool Update(WordSuite wordSuite)
        {
            using (var uow = _unitOfWorkFactory.GetUnitOfWork())
            {
                var oldWordSuite = uow.WordSuiteRepository.GetById(wordSuite.Id);
                oldWordSuite.Name = wordSuite.Name;
                oldWordSuite.Threshold = wordSuite.Threshold;
                oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime;

                uow.WordSuiteRepository.Update(oldWordSuite);
                uow.Save();
            }
            //using (var context = new WorldOfWordsDatabaseContext())
            //{
            //    var oldWordSuite = context.WordSuites.First(ws => ws.Id == wordSuite.Id);
            //    oldWordSuite.Name = wordSuite.Name;
            //    oldWordSuite.Threshold = wordSuite.Threshold;
            //    oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime;

            //    context.WordSuites.AddOrUpdate(oldWordSuite);
            //    context.SaveChanges();
            //}
            return true;
        }
Esempio n. 9
0
        public bool Update(WordSuite wordSuite)
        {
            using (var context = new WorldOfWordsDatabaseContext())
            {
                var oldWordSuite = context.WordSuites.First(ws => ws.Id == wordSuite.Id);
                oldWordSuite.Name = wordSuite.Name;
                oldWordSuite.Threshold = wordSuite.Threshold;
                oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime;

                context.WordSuites.AddOrUpdate(oldWordSuite);
                context.SaveChanges();
            }
            return true;
        }
        public void TrainingWordSuiteController_GetTest()
        {
            //Arrange
            var initial = new WordSuite()
            {
                Id = 1,
                Name = "Days of the week"
            };

            var expected = new TrainingWordSuiteModel()
            {
                Id = 1,
                Name = "Days of the week",
                WordTranslations = new List<WordTranslationModel>()
                        {
                            new WordTranslationModel
                            {
                                Id = 1, OriginalWord = "sunday"
                            },
                            new WordTranslationModel
                            {
                                Id = 1, OriginalWord = "monday"
                            }
                        }
            };
            //Action
            Mock<IQuizWordSuiteMapper> testWordSuiteMapper = new Mock<IQuizWordSuiteMapper>();
            Mock<ITrainingWordSuiteMapper> trainingWordSuiteMapper = new Mock<ITrainingWordSuiteMapper>();
            Mock<IWordSuiteService> wordSuiteService = new Mock<IWordSuiteService>();
            Mock<IWordProgressService> progressService = new Mock<IWordProgressService>();
            Mock<IWordProgressMapper> progressMapper = new Mock<IWordProgressMapper>();
            GenerateData("1", new[] { "NoRoles" });
            TrainingWordSuiteController Controller = new TrainingWordSuiteController(testWordSuiteMapper.Object,
                trainingWordSuiteMapper.Object,
                wordSuiteService.Object,
                progressService.Object,
                progressMapper.Object);
            wordSuiteService.Setup(x => x.GetWithNotStudiedWords(1)).Returns(initial);
            testWordSuiteMapper
                   .Setup(x => x.Map(initial))
                    .Returns(expected);
            var actual = Controller.GetTask(1);

            //Assert
            //Assert.AreEqual(expected, actual);
        }
        public void TrainingWordSuiteController_Check()
        {
            //Arrange
            var initial = new WordSuite()
            {
                Id = 1,
                Name = "Days of the week",
            };

            var data = new TrainingWordSuiteModel()
            {
                Id = 1,
                Name = "Days of the week",
                QuizStartTime = DateTime.Now,
                QuizResponseTime = 10,
                WordTranslations = new List<WordTranslationModel>()
                {
                            new WordTranslationModel
                            {
                                Id = 1, OriginalWord = "sunday", TranslationWord = "sunday"
                            },
                            new WordTranslationModel
                            {
                                Id = 1, OriginalWord = "monday", TranslationWord = "monday"
                            }
                        }
            };

            var expected = new TrainingWordSuiteModel()
            {
                Id = 1,
                Name = "Days of the week",
                QuizStartTime = DateTime.Now,
                QuizResponseTime = 10,
                WordTranslations = new List<WordTranslationModel>()
                        {
                            new WordTranslationModel
                            {
                                Id = 1, OriginalWord = "sunday", TranslationWord = "неділя"
                            },
                            new WordTranslationModel
                            {
                                Id = 1, OriginalWord = "monday", TranslationWord = "понеділок"
                            }
                        }
            };

            //Action
            Mock<IQuizWordSuiteMapper> testWordSuiteMapper = new Mock<IQuizWordSuiteMapper>();
            Mock<ITrainingWordSuiteMapper> trainingWordSuiteMapper = new Mock<ITrainingWordSuiteMapper>();
            Mock<IWordSuiteService> wordSuiteService = new Mock<IWordSuiteService>();
            Mock<IWordProgressService> progressService = new Mock<IWordProgressService>();
            Mock<IWordProgressMapper> progressMapper = new Mock<IWordProgressMapper>();
            GenerateData("1", new[] { "NoRoles" });
            TrainingWordSuiteController Controller = new TrainingWordSuiteController(testWordSuiteMapper.Object,
                trainingWordSuiteMapper.Object,
                wordSuiteService.Object,
                progressService.Object,
                progressMapper.Object);
              wordSuiteService.Setup(x => x.GetWithNotStudiedWords(1)).Returns(initial);
            trainingWordSuiteMapper
                   .Setup(x => x.Map(initial))
                    .Returns(expected);
            progressService.Setup(x => x.IncrementProgress(It.IsAny<int>(), It.IsAny<int>())).Returns(true);

            var actual = Controller.CheckTask(data);

            //Assert
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult<TrainingWordSuiteModel>), actual);
        }
        public void MapForEditTest()
        {
            // Arrange
            WordSuite initial = new WordSuite
            {
                Id = 100,
                Name = "WordSuite",
                Language = new Language { Name = "English" },
                LanguageId = 200,
                PrototypeId = 300,
                Threshold = 50,
                QuizResponseTime = 10
            };

            // Act
            WordSuiteEditModel result = (new WordSuiteMapper()).MapForEdit(initial);

            // Assert
            Assert.AreEqual(initial.Id, result.Id);
            Assert.AreEqual(initial.Name, result.Name);
            Assert.AreEqual(initial.Language.Name, result.Language);
            Assert.AreEqual(initial.LanguageId, result.LanguageId);
            Assert.AreEqual(initial.PrototypeId, result.PrototypeId);
            Assert.AreEqual(initial.Threshold, result.Threshold);
            Assert.AreEqual(initial.QuizResponseTime, result.QuizResponseTime);
        }
        public bool Update(WordSuite wordSuite)
        {
            using (var uow = _unitOfWorkFactory.GetUnitOfWork())
            {
                var oldWordSuite = uow.WordSuiteRepository.GetById(wordSuite.Id);
                oldWordSuite.Name = wordSuite.Name;
                oldWordSuite.Threshold = wordSuite.Threshold;
                oldWordSuite.QuizResponseTime = wordSuite.QuizResponseTime;

                uow.WordSuiteRepository.Update(oldWordSuite);
                uow.Save();
            }
            return true;
        }
 public int Add(WordSuite wordSuite)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         uow.WordSuiteRepository.AddOrUpdate(wordSuite);
         uow.Save();
         return wordSuite.Id;
     }
 }
 public async Task<bool> CopyWordsuitesForTeacherListByIdAsync(List<int> teacherIds, int wordSuiteId)
 {
     using (var uow = _unitOfWorkFactory.GetUnitOfWork())
     {
         WordSuite wordSuite = await uow.WordSuiteRepository.GetByIdAsync(wordSuiteId);
         if (wordSuite == null)
         {
             throw new ArgumentException("Word Suite with id you are requesting does not exist");
         }
         User teacherWhoShare = await uow.UserRepository.GetByIdAsync(wordSuite.OwnerId);
         List<WordProgress> wordProgresses = await uow.WordProgressRepository.GetAll().Where(t => t.WordSuiteId == wordSuiteId).ToListAsync();
         
         List<WordSuite> wordSuitesToCopy = new List<WordSuite>();
         foreach (int teacherId in teacherIds)
         {
             WordSuite wordSuiteToCopy = new WordSuite
             {
                 Name = wordSuite.Name + "_(Shared_by_" + teacherWhoShare.Name + ")",
                 LanguageId = wordSuite.LanguageId,
                 Threshold = wordSuite.Threshold,
                 QuizResponseTime = wordSuite.QuizResponseTime,
                 QuizStartTime = wordSuite.QuizStartTime,
                 OwnerId = teacherId,
                 PrototypeId = null
             };
             wordSuitesToCopy.Add(wordSuiteToCopy);
         };
         List<WordTranslation> wordTranslationsToCopy = new List<WordTranslation>();
         foreach (var wordProgress in wordProgresses)
         {
             wordTranslationsToCopy.Add(wordProgress.WordTranslation);
         }
         List<WordProgress> WordProgressList = new List<WordProgress>();
         foreach (var wordTranslation in wordTranslationsToCopy)
         {
             foreach (var wordSuiteToCopy in wordSuitesToCopy)
             {
                 WordProgress wordProgress = new WordProgress { WordSuite = wordSuiteToCopy, WordTranslation = wordTranslation };
                 WordProgressList.Add(wordProgress);
             }
         }
         uow.WordSuiteRepository.Add(wordSuitesToCopy);
         uow.WordProgressRepository.Add(WordProgressList);
         await uow.SaveAsync();
         return true;
     }
 }