Beispiel #1
0
        public async Task Add(Blog item)
        {
            _db.Blogs.Add(item);
            await _db.SaveChangesAsync();

            if (AppSettings.InitializeData)
            {
                var initializer = new DataInitializer();
                initializer.SeedPosts(item);
            }
        }
Beispiel #2
0
        public async Task Add(Post item)
        {
            using (var context = new BlogiFireContext())
            {
                await context.Posts.AddAsync(item);

                await context.SaveChangesAsync();
            }
        }
Beispiel #3
0
        public async Task Delete(int id)
        {
            using (var context = new BlogiFireContext())
            {
                var item = await context.Posts.FirstOrDefaultAsync(i => i.Id == id);

                context.Posts.Remove(item);
                await context.SaveChangesAsync();
            }
        }
Beispiel #4
0
        public async Task Add(Comment item)
        {
            using (var context = new BlogiFireContext())
            {
                await context.Comments.AddAsync(item);

                // update comment count
                if (item.PostId > 0)
                {
                    var post = context.Posts.Where(p => p.Id == item.PostId).FirstOrDefault();
                    post.Comments++;
                    await context.Posts.UpdateAsync(post);
                }
                await context.SaveChangesAsync();
            }
        }
Beispiel #5
0
        public async Task Update(Post item)
        {
            using (var context = new BlogiFireContext())
            {
                var itemToUpdate = await context.Posts.FirstOrDefaultAsync(i => i.Id == item.Id);

                itemToUpdate.Saved     = DateTime.UtcNow;
                itemToUpdate.Title     = item.Title;
                itemToUpdate.Content   = item.Content;
                itemToUpdate.Tags      = item.Tags;
                itemToUpdate.Published = item.Published;

                await context.Posts.UpdateAsync(itemToUpdate);

                await context.SaveChangesAsync();
            }
        }
Beispiel #6
0
        public async Task Delete(int id)
        {
            using (var context = new BlogiFireContext())
            {
                var item = await context.Comments.FirstOrDefaultAsync(i => i.Id == id);

                context.Comments.Remove(item);

                // update comment count
                if (item.PostId > 0)
                {
                    var post = context.Posts.Where(p => p.Id == item.PostId).FirstOrDefault();
                    post.Comments--;
                    await context.Posts.UpdateAsync(post);
                }
                await context.SaveChangesAsync();
            }
        }
Beispiel #7
0
        public async Task Update(Comment item)
        {
            using (var context = new BlogiFireContext())
            {
                var itemToUpdate = await context.Comments.FirstOrDefaultAsync(i => i.Id == item.Id);

                itemToUpdate.Author     = item.Author;
                itemToUpdate.Content    = item.Content;
                itemToUpdate.Ip         = item.Ip;
                itemToUpdate.Website    = item.Website;
                itemToUpdate.UserAgent  = item.UserAgent;
                itemToUpdate.Published  = item.Published;
                itemToUpdate.IsApproved = item.IsApproved;

                await context.Comments.UpdateAsync(itemToUpdate);

                await context.SaveChangesAsync();
            }
        }