public async Task <PhrasesPair> RemovePhrasesPair(PhrasesPair phrasesPair) { var res = this.PhrasesPairs.Remove(phrasesPair); var firstPhrase = await this.Phrases.FirstOrDefaultAsync(p => p.Id == res.FirstPhraseId); this.Phrases.Remove(firstPhrase); var secondPhrase = await this.Phrases.FirstOrDefaultAsync(p => p.Id == res.SecondPhraseId); this.Phrases.Remove(secondPhrase); return(res); }
public async Task <HttpResponseMessage> CreatePhrasesPair(PhrasesPairViewModel vm) { var firstPhrase = new Phrase() { Text = vm.FirstPhrase.Text, Description = vm.FirstPhrase.Description, Language = vm.FirstPhrase.Language, OwnerId = User.Identity.Name }; var secondPhrase = new Phrase() { Text = vm.SecondPhrase.Text, Description = vm.SecondPhrase.Description, Language = vm.SecondPhrase.Language, OwnerId = User.Identity.Name }; var firstPhraseId = _dbContext.CreatePhrase(firstPhrase).Id; var secondPhraseId = _dbContext.CreatePhrase(secondPhrase).Id; var phrasesPair = new PhrasesPair() { CreationDate = DateTime.Now, DictionaryId = vm.DictionaryId, FirstPhraseId = firstPhraseId, SecondPhraseId = secondPhraseId, OwnerId = User.Identity.Name, IsConfirmed = false }; _dbContext.CreatePhrasesPair(phrasesPair); var dictionary = await _dbContext.Dictionaries.FirstOrDefaultAsync(d => d.Id == vm.DictionaryId); dictionary.LastChangeDate = DateTime.Now; await _dbContext.SaveDbChangesAsync(); return(Request.CreateResponse(HttpStatusCode.OK, phrasesPair)); }
public PhrasesPair CreatePhrasesPair(PhrasesPair phrasesPair) { return(this.PhrasesPairs.Add(phrasesPair)); }