public async Task <UserCategory> Insert(UserCategory userCategory) { _context.Add(userCategory); await _context.SaveChangesAsync(); return(userCategory); }
public async Task <int> DeleteByIdAsync(long id) { var category = await GetById(id); _context.Categories.Remove(category); int removed = await _context.SaveChangesAsync(); return(removed); }
public async Task <int> DeleteByIdAsync(long id) { var post = await GetById(id); _context.Posts.Remove(post); int removed = await _context.SaveChangesAsync(); return(removed); }
public async Task Create(T entity) { using var context = new BlogAppContext(); await context.AddAsync(entity); await context.SaveChangesAsync(); }
public async Task <bool> AddPostAsync(AddPostViewModel model, string authorId) { var post = _mapper.Map <Post>(model); post.Author = await _context.Users.FindAsync(authorId); if (post == null) { throw new Exception("Model is empty"); } _context.Add(post); var success = await _context.SaveChangesAsync() > 0; if (success) { return(true); } throw new Exception("Problem saving changes"); }
public async Task AddAsync(TEntity entity) { await _context.AddAsync(entity); await _context.SaveChangesAsync(); }
public async Task Update(T entity) { using var context = new BlogAppContext(); context.Update(entity); await context.SaveChangesAsync(); }