public async Task <Post> Insert(Post post) { _context.Add(post); await _context.SaveChangesAsync(); return(post); }
public async Task <Category> Insert(Category category) { _context.Add(category); await _context.SaveChangesAsync(); return(category); }
public async Task <UserCategory> Insert(UserCategory userCategory) { _context.Add(userCategory); await _context.SaveChangesAsync(); return(userCategory); }
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"); }