コード例 #1
0
        public async Task <WordCreateResult> CreateWord(WordCreate model)
        {
            await validator.ValidateCreateModel(model);

            var newWord = mapper.MapWord(model);
            await context.Words.AddAsync(newWord);

            await context.SaveChangesAsync();

            return(new WordCreateResult()
            {
                WordId = newWord.Id
            });
        }
コード例 #2
0
        public async Task <WordUpdateResult> UpdateWord(WordUpdate model)
        {
            await validator.ValidateUpdateModel(model);

            var toUpdate = await context.Words.SingleOrDefaultAsync(x => x.Id == model.Id);

            if (toUpdate == null)
            {
                throw new ArgumentException($"Can't find word with id {model.Id}");
            }

            toUpdate = mapper.MapWord(toUpdate, model);

            await context.SaveChangesAsync();

            var wordModel = await wordProvider.GetWord(model.Id);

            return(new WordUpdateResult()
            {
                Word = wordModel
            });
        }