Esempio n. 1
0
 public WordCreatedEvent(Word word)
 {
     Word = word;
 }
Esempio n. 2
0
        public HangerdResult<WordDto> AddWord(string stem)
        {
            return TryOperate(() =>
            {
                if (string.IsNullOrWhiteSpace(stem))
                    throw new HangerdException("词干不可为空");

                using (var unitOfWork = DbContextFactory.CreateContext())
                {
                    var wordRepository = unitOfWork.GetRepository<IWordRepository>();
                    var word = wordRepository.GetWordByStem(stem, false);

                    if (word != null)
                        throw new HangerdException("该单词已存在");

                    word = new Word(stem);

                    wordRepository.Add(word);

                    unitOfWork.Commit();

                    return Mapper.Map<Word, WordDto>(word);
                }
            });
        }