Пример #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();
 }