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 }); }
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 }); }