예제 #1
0
        public static async Task Update(ApplicationDbContext context, JGN_Blogs entity)
        {
            Validation(entity);
            ScreenContent(context, entity);
            var item = context.JGN_Blogs
                       .Where(p => p.id == entity.id)
                       .FirstOrDefault();

            if (item != null)
            {
                item.title           = UtilityBLL.processNull(entity.title, 0);
                item.description     = UtilityBLL.processNull(entity.description, 0);
                item.tags            = UtilityBLL.processNull(entity.tags, 0);
                item.picture_url     = UtilityBLL.processNull(entity.picture_url, 0);
                item.picture_caption = UtilityBLL.processNull(entity.picture_caption, 0);

                context.Entry(item).State = EntityState.Modified;
                await context.SaveChangesAsync();

                // Content Associated Categories Processing
                CategoryContentsBLL.ProcessAssociatedContentCategories(context, entity.categories,
                                                                       item.id, (byte)CategoryContentsBLL.Types.Blogs, true);
                // update user stats
                await update_stats(context, entity.userid);
            }
        }
예제 #2
0
        public static async Task <JGN_Blogs> Add(ApplicationDbContext context, JGN_Blogs entity)
        {
            Validation(entity);
            ScreenContent(context, entity);

            var ent = new JGN_Blogs()
            {
                userid          = entity.userid,
                title           = entity.title,
                description     = entity.description,
                tags            = entity.tags,
                isenabled       = (byte)entity.isenabled,
                isapproved      = (byte)entity.isapproved,
                created_at      = DateTime.Now,
                fetch_url       = UtilityBLL.processNull(entity.fetch_url, 0),
                picture_url     = UtilityBLL.processNull(entity.picture_url, 0),
                cover_url       = UtilityBLL.processNull(entity.cover_url, 0),
                picture_caption = UtilityBLL.processNull(entity.picture_caption, 0),
            };

            context.Entry(ent).State = EntityState.Added;
            await context.SaveChangesAsync();

            entity.id = ent.id;

            // Content Associated Categories Processing
            CategoryContentsBLL.ProcessAssociatedContentCategories(context, entity.categories,
                                                                   entity.id, (byte)CategoryContentsBLL.Types.Blogs, false);

            // update user stats
            await update_stats(context, entity.userid);

            return(entity);
        }