public async Task <DataResult <WordModel> > UpdateWordAsync(WordModel word) { using (var context = new LangiumDbContext()) { try { context.Entry(word).State = EntityState.Modified; context.Entry(word.Lexeme).State = EntityState.Modified; context.Entry(word.Transcription).State = EntityState.Modified; context.Entry(word.Translation).State = EntityState.Modified; await context.SaveChangesAsync(); var updatedWord = context.Words.FirstOrDefault(w => w.Id == word.Id); return(new DataResult <WordModel>(updatedWord)); } catch (Exception ex) { return(new DataResult <WordModel>(ex, ex.InnerException.Message)); } } }
public async Task <DataResult <UserModel> > UpdateUserAsync(UserModel user) { using (var context = new LangiumDbContext()) { try { context.Entry(user).State = EntityState.Modified; await context.SaveChangesAsync(); var updatedUser = context.Users.FirstOrDefault(u => u.Id == user.Id); return(new DataResult <UserModel> (updatedUser)); } catch (Exception ex) { return(new DataResult <UserModel>(ex, ex.InnerException.Message)); } } }
public async Task <DataResult <CategoryModel> > UpdateCategoryAsync(CategoryModel category) { using (var context = new LangiumDbContext()) { try { context.Entry(category).State = EntityState.Modified; await context.SaveChangesAsync(); var updatedCategory = context.Categories.FirstOrDefault(c => c.Id == category.Id); return(new DataResult <CategoryModel>(updatedCategory)); } catch (Exception ex) { return(new DataResult <CategoryModel>(ex, ex.InnerException.Message)); } } }