示例#1
0
        public bool Create(string native, string foreign, Guid groupId)
        {
            if (!_validateFlashcard.Validate(foreign, native))
            {
                UserMessages.AddRange(_validateFlashcard.GetErrorMessages());
                return(false);
            }

            if (!_checkIfFlashcardIsUnique.IsUnique(foreign, native, groupId))
            {
                UserMessages.Add("Flashcard already exists.");
                return(false);
            }

            Guid newId;

            do
            {
                newId = Guid.NewGuid();
            } while (!_checkIfFlashcardIdIsUnique.Check(newId));

            FlashcardDbModel modelA = new FlashcardDbModel()
            {
                Id = newId,
                ForeignLanguage   = foreign,
                NativeLanguage    = native,
                GroupDbModelId    = groupId,
                NextPracticeDate  = DateTime.Now.Date,
                PracticeDirection = PracticeDirection.FromForeignToNative
            };

            FlashcardDbModel modelB = new FlashcardDbModel()
            {
                Id = newId,
                ForeignLanguage   = foreign,
                NativeLanguage    = native,
                GroupDbModelId    = groupId,
                NextPracticeDate  = DateTime.Now.Date,
                PracticeDirection = PracticeDirection.FromNativeToForeign
            };


            _insertNewFlashcard.Insert(modelA);
            _insertNewFlashcard.Insert(modelB);

            return(true);
        }
示例#2
0
        public bool Update(string native, string foreign, Guid flashcardId, Guid groupId)
        {
            if (!_validateFlashcard.Validate(foreign, native))
            {
                UserMessages.AddRange(_validateFlashcard.GetErrorMessages());
                return(false);
            }

            if (!_checkIfFlashcardIsUnique.IsUnique(foreign, native, groupId))
            {
                UserMessages.Add("Flashcard already exists.");
                return(false);
            }

            _updateFlashcardWords.Update(flashcardId, native, foreign);

            return(true);
        }