Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post(WordSuiteEditModel wordSuite)
        {
            if (wordSuite == null)
            {
                throw new ArgumentNullException("wordSuite", "WordSuite can't be null");
            }

            if (wordSuite.IsBasicInfoChanged)
            {
                if (!wordSuiteService.Update(wordSuiteMapper.Map(wordSuite)))
                {
                    return(BadRequest("Failed to edit WordSuite"));
                }
            }

            if (wordSuite.AreProhibitedQuizzesChanged)
            {
                if (!wordSuiteService.UpdateProhibitedQuizzes(wordSuite.Id, wordSuite.ProhibitedQuizzesId))
                {
                    return(BadRequest("Failed to change ProhibitedQuizzes in wordSuite"));
                }
            }

            if (wordSuite.WordTranslationsToDeleteIdRange != null)
            {
                if (wordSuite.WordTranslationsToDeleteIdRange.Count > 0)
                {
                    if (!wordProgressService.RemoveRange(wordProgressMapper.MapRange(wordSuite.Id, wordSuite.WordTranslationsToDeleteIdRange)))
                    {
                        return(BadRequest("Failed to remove WordTranslations"));
                    }
                }
            }

            if (wordSuite.WordTranslationsToAddIdRange != null)
            {
                if (wordSuite.WordTranslationsToAddIdRange.Count > 0)
                {
                    if (!wordProgressService.AddRange(wordProgressMapper.MapRange(wordSuite.Id, wordSuite.WordTranslationsToAddIdRange)))
                    {
                        return(BadRequest("Failed to add WordTranslations"));
                    }
                }
            }

            return(Ok());
        }