Esempio n. 1
0
        public async Task <Post> Insert(Post post)
        {
            _context.Add(post);
            await _context.SaveChangesAsync();

            return(post);
        }
Esempio n. 2
0
        public async Task <Category> Insert(Category category)
        {
            _context.Add(category);
            await _context.SaveChangesAsync();

            return(category);
        }
Esempio n. 3
0
        public async Task <UserCategory> Insert(UserCategory userCategory)
        {
            _context.Add(userCategory);
            await _context.SaveChangesAsync();

            return(userCategory);
        }
Esempio n. 4
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");
        }