예제 #1
0
        public async Task <UserCategory> Insert(UserCategory userCategory)
        {
            _context.Add(userCategory);
            await _context.SaveChangesAsync();

            return(userCategory);
        }
예제 #2
0
        public async Task <int> DeleteByIdAsync(long id)
        {
            var category = await GetById(id);

            _context.Categories.Remove(category);
            int removed = await _context.SaveChangesAsync();

            return(removed);
        }
예제 #3
0
        public async Task <int> DeleteByIdAsync(long id)
        {
            var post = await GetById(id);

            _context.Posts.Remove(post);
            int removed = await _context.SaveChangesAsync();

            return(removed);
        }
예제 #4
0
        public async Task Create(T entity)
        {
            using var context = new BlogAppContext();
            await context.AddAsync(entity);

            await context.SaveChangesAsync();
        }
예제 #5
0
        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");
        }
예제 #6
0
        public async Task AddAsync(TEntity entity)
        {
            await _context.AddAsync(entity);

            await _context.SaveChangesAsync();
        }
예제 #7
0
 public async Task Update(T entity)
 {
     using var context = new BlogAppContext();
     context.Update(entity);
     await context.SaveChangesAsync();
 }