Beispiel #1
0
 public JsonResult AddToSerie(int?id, int?seriid)
 {
     if (id == null || seriid == null)
     {
         Response.StatusCode = 500;
         return(Json(new { Message = "Lỗi" }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         using (DVCPContext conn = new DVCPContext())
         {
             Series sr   = conn.Series.Find(seriid);
             Post   post = conn.Posts.Find(id);
             foreach (var x in sr.Tbl_POST)
             {
                 if (x.post_id.Equals(id))
                 {
                     Response.StatusCode = 500;
                     return(Json(new { Message = "Trùng lặp bài viết" }, JsonRequestBehavior.AllowGet));
                 }
             }
             sr.Tbl_POST.Add(post);
             post.Tbl_Series.Add(sr);
             conn.SaveChanges();
         }
         return(Json(new { Message = "Thêm thành công" }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #2
0
        protected override void Seed(DVCPContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            context.WebInfo.AddOrUpdate(x => x.id,
                                        new WebInfo
            {
                id        = 1,
                web_name  = "Đại Việt Cổ Phong",
                web_des   = "Trang web chính thức của Đại Việt Cổ Phong",
                web_about = "Về Đại Việt Cổ Phong",
            }
                                        );
            context.Users.AddOrUpdate(x => x.username,
                                      new User
            {
                username = "******",
                password = "******",     // = admin123
                fullname = "ADMIN ĐVCP",
                userrole = "admin",
                status   = true,
            }
                                      );
            context.Tags.AddOrUpdate(x => x.TagID,
                                     new Tag {
                TagID = 1, TagName = "Kiến trúc"
            },
                                     new Tag {
                TagID = 2, TagName = "Chất liệu"
            },
                                     new Tag {
                TagID = 3, TagName = "Binh bị"
            },
                                     new Tag {
                TagID = 4, TagName = "Quân sự"
            },
                                     new Tag {
                TagID = 5, TagName = "Thần thoại"
            },
                                     new Tag {
                TagID = 6, TagName = "Văn hóa"
            },
                                     new Tag {
                TagID = 7, TagName = "Phong tục"
            },
                                     new Tag {
                TagID = 8, TagName = "Tôn giáo"
            },
                                     new Tag {
                TagID = 9, TagName = "Trang phục"
            }
                                     );
            context.SaveChanges();
        }
Beispiel #3
0
 public JsonResult RemoveFromSerie(int?id, int?seriid)
 {
     if (id == null || seriid == null)
     {
         Response.StatusCode = 500;
         return(Json(new { Message = "Lỗi" }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         using (DVCPContext conn = new DVCPContext())
         {
             Series sr   = conn.Series.Find(seriid);
             Post   post = conn.Posts.Find(id);
             sr.Tbl_POST.Remove(post);
             post.Tbl_Series.Remove(sr);
             conn.SaveChanges();
         }
         return(Json(new { Message = "Remove thành công" }, JsonRequestBehavior.AllowGet));
     }
 }
Beispiel #4
0
        public ActionResult Category(int?id, int?page)
        {
            if (id != null)
            {
                int pageSize  = 15;
                int pageIndex = 1;
                //IPagedList<Tbl_POST> post = null;
                pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
                Tag tag = db.tagRepository.FindByID(id.Value);
                if (tag != null)
                {
                    using (DVCPContext conn = db.Context)
                    {
                        var result = (
                            // instance from context
                            from a in conn.Tags
                            // instance from navigation property
                            from b in a.Tbl_POST
                            //join to bring useful data
                            join c in conn.Posts on b.post_id equals c.post_id
                            where a.TagID == id && b.status == true
                            orderby b.create_date descending
                            select new lstPostViewModel
                        {
                            post_id = c.post_id,
                            post_title = c.post_title,
                            post_teaser = c.post_teaser,
                            ViewCount = c.ViewCount,
                            AvatarImage = c.AvatarImage,
                            create_date = c.create_date,
                            slug = c.post_slug
                        }).ToPagedList(pageIndex, pageSize);
                        ViewBag.catname = tag.TagName;
                        return(View(result));
                    }
                }
                return(HttpNotFound());
            }

            return(View("CategoryAll"));
        }
Beispiel #5
0
        public ActionResult SerieDetail(int id, string name)
        {
            Series sr = db.seriesRepository.FindByID(id);

            if (sr != null)
            {
                if (!String.IsNullOrWhiteSpace(name))
                {
                    using (DVCPContext conn = new DVCPContext())
                    {
                        var result = (
                            // instance from context
                            from a in conn.Series
                            // instance from navigation property
                            from b in a.Tbl_POST
                            //join to bring useful data
                            join c in conn.Posts on b.post_id equals c.post_id
                            //where a.seriesID == c.Tbl_Series.s
                            where a.seriesID.Equals(id)
                            where b.post_title.Contains(name)
                            select new ViewModel.SeriesPost
                        {
                            post_id = b.post_id,
                            post_title = b.post_title,
                            status = b.status,
                            ViewCount = b.ViewCount,
                            userid = b.ViewCount,
                            create_date = b.create_date,
                            userfullname = b.tbl_User.fullname,
                            username = b.tbl_User.username,
                            slug = b.post_slug
                        }).ToList();
                        SeriesPostViewModel postViewModel = new SeriesPostViewModel
                        {
                            SerieID   = sr.seriesID,
                            SerieName = sr.seriesName,
                            ListPost  = result,
                        };
                        return(View(postViewModel));
                    }
                }
                else
                {
                    ViewBag.name = name;
                    using (DVCPContext conn = new DVCPContext())
                    {
                        var result = (
                            // instance from context
                            from a in conn.Series
                            // instance from navigation property
                            from b in a.Tbl_POST
                            //join to bring useful data
                            join c in conn.Posts on b.post_id equals c.post_id
                            //where a.seriesID == c.Tbl_Series.s
                            where a.seriesID.Equals(id)
                            select new ViewModel.SeriesPost
                        {
                            post_id = b.post_id,
                            post_title = b.post_title,
                            status = b.status,
                            ViewCount = b.ViewCount,
                            userid = b.ViewCount,
                            create_date = b.create_date,
                            userfullname = b.tbl_User.fullname,
                            username = b.tbl_User.username,
                        }).ToList();
                        SeriesPostViewModel postViewModel = new SeriesPostViewModel
                        {
                            SerieID   = sr.seriesID,
                            SerieName = sr.seriesName,
                            ListPost  = result,
                        };
                        return(View(postViewModel));
                    }
                }
                //return View(postlist);
            }
            return(RedirectToAction("ListSeries"));
        }
Beispiel #6
0
        public ActionResult Search(SearchViewModel model, int?page)
        {
            int pageSize  = 8;
            int pageIndex = 1;

            pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;
            IPagedList <lstPostViewModel> post = new List <lstPostViewModel>().ToPagedList(pageIndex, pageSize);
            List <Tag> taglist = new List <Tag>();

            taglist.AddRange(model.post_tag.Where(m => m.Selected)
                             .Select(m => new Tag {
                TagID = int.Parse(m.Value), TagName = m.Text
            })
                             );
            ViewBag.stitle = model.title;
            bool title   = String.IsNullOrWhiteSpace(model.title);
            bool tag     = taglist.Count == 0;
            bool dynasty = model.Dynasty == null;
            var  check   = 0;

            if (title && tag && dynasty)
            {
                // cả 3 cái đều null
                check = 1;
            }
            else if (!title && !tag && !dynasty)
            {
                // cả 3 cái đều ko null
                check = 2;
            }
            else if (!title && tag && dynasty)
            {
                // chỉ title
                check = 3;
            }
            else if (title && !tag && dynasty)
            {
                // chỉ tag
                check = 4;
            }
            else if (title && tag && !dynasty)
            {
                // chỉ DN
                check = 5;
            }
            else if (!title && !tag && dynasty)
            {
                // title và tag
                check = 6;
            }
            else if (!title && tag && !dynasty)
            {
                // title và dn
                check = 7;
            }
            else if (title && !tag && !dynasty)
            {
                // tag và dn
                check = 8;
            }
            switch (check)
            {
            default:
            case 1:
                IQueryable <Post> x = db.postRepository.AllPosts()
                                      .Where(m => m.status)
                                      .OrderByDescending(m => m.create_date);
                post =
                    x.Select(m => new lstPostViewModel
                {
                    post_id     = m.post_id,
                    post_title  = m.post_title,
                    post_teaser = m.post_teaser,
                    ViewCount   = m.ViewCount,
                    AvatarImage = m.AvatarImage,
                    create_date = m.create_date,
                    tagsname    = m.Tbl_Tags.FirstOrDefault().TagName,
                    slug        = m.post_slug
                }
                             ).ToPagedList(pageIndex, pageSize);
                break;

            case 2:
                using (DVCPContext conn = db.Context)
                {
                    var query = (
                        // instance from context
                        from z in taglist
                        // join list tìm kiếm
                        join a in conn.Tags on z.TagID equals a.TagID
                        // instance from navigation property
                        from b in a.Tbl_POST
                        // join to bring useful data
                        join c in conn.Posts on b.post_id equals c.post_id
                        where c.status == true
                        where c.dynasty == model.Dynasty.ToString()
                        where c.post_title.ToLower().Contains(model.title.ToLower())
                        // sắp theo
                        orderby c.Rated
                        select new
                    {
                        c.post_id,
                        c.post_title,
                        c.post_teaser,
                        c.ViewCount,
                        c.AvatarImage,
                        c.create_date,
                        c.Tbl_Tags.FirstOrDefault().TagName,
                        c.post_slug
                    }).Distinct();
                    //DISTINCT ĐỂ SAU KHI SELECT ĐỐI TƯỢNG MỚI ĐƯỢC
                    //VÌ THẰNG DƯỚI KHÔNG EQUAL HASHCODE
                    post = query.Select(c => new lstPostViewModel
                    {
                        post_id     = c.post_id,
                        post_title  = c.post_title,
                        post_teaser = c.post_teaser,
                        ViewCount   = c.ViewCount,
                        AvatarImage = c.AvatarImage,
                        create_date = c.create_date,
                        tagsname    = c.TagName,
                        slug        = c.post_slug
                    }).ToPagedList(pageIndex, pageSize);
                }
                break;

            case 3:
                var p = db.postRepository.AllPosts()
                        .Where(m => m.status)
                        .Where(m => m.post_title.Contains(model.title))
                        .OrderBy(m => m.post_title.Contains(model.title));
                post =
                    p.Select(m => new lstPostViewModel
                {
                    post_id     = m.post_id,
                    post_title  = m.post_title,
                    post_teaser = m.post_teaser,
                    ViewCount   = m.ViewCount,
                    AvatarImage = m.AvatarImage,
                    create_date = m.create_date,
                    tagsname    = m.Tbl_Tags.FirstOrDefault().TagName,
                    slug        = m.post_slug
                }
                             ).ToPagedList(pageIndex, pageSize);
                break;

            case 4:
                using (DVCPContext conn = db.Context)
                {
                    post = (
                        // instance from context
                        from z in taglist
                        // join list tìm kiếm
                        join a in conn.Tags on z.TagID equals a.TagID
                        // instance from navigation property
                        from b in a.Tbl_POST
                        //join to bring useful data
                        join c in conn.Posts on b.post_id equals c.post_id
                        where c.status == true
                        // sắp theo ngày đăng mới nhất
                        orderby b.create_date descending
                        select new
                    {
                        c.post_id,
                        c.post_title,
                        c.post_teaser,
                        c.ViewCount,
                        c.AvatarImage,
                        c.create_date,
                        c.Tbl_Tags.FirstOrDefault().TagName,
                        c.post_slug
                    })
                           //DISTINCT ĐỂ SAU KHI SELECT ĐỐI TƯỢNG MỚI ĐƯỢC
                           //VÌ THẰNG DƯỚI KHÔNG EQUAL HASHCODE
                           .Distinct().Select(c => new lstPostViewModel
                    {
                        post_id     = c.post_id,
                        post_title  = c.post_title,
                        post_teaser = c.post_teaser,
                        ViewCount   = c.ViewCount,
                        AvatarImage = c.AvatarImage,
                        create_date = c.create_date,
                        tagsname    = c.TagName,
                        slug        = c.post_slug
                    })
                           .ToPagedList(pageIndex, pageSize);
                }
                break;

            case 5:
                post = db.postRepository.AllPosts()
                       .Where(m => m.status)
                       .Where(m => m.dynasty.Equals(model.Dynasty.ToString()))
                       .OrderByDescending(m => m.create_date)
                       .Select(m => new lstPostViewModel
                {
                    post_id     = m.post_id,
                    post_title  = m.post_title,
                    post_teaser = m.post_teaser,
                    ViewCount   = m.ViewCount,
                    AvatarImage = m.AvatarImage,
                    create_date = m.create_date,
                    tagsname    = m.Tbl_Tags.FirstOrDefault().TagName,
                    slug        = m.post_slug
                }
                               ).ToPagedList(pageIndex, pageSize);
                break;

            case 6:
                using (DVCPContext conn = db.Context)
                {
                    post = (
                        // instance from context
                        from z in taglist
                        // join list tìm kiếm
                        join a in conn.Tags on z.TagID equals a.TagID
                        // instance from navigation property
                        from b in a.Tbl_POST
                        //join to bring useful data
                        join c in conn.Posts on b.post_id equals c.post_id
                        where c.post_title.ToLower().Contains(model.title.ToLower())
                        where c.status == true
                        // sắp theo so khớp
                        orderby c.post_title.Contains(model.title)
                        select new
                    {
                        c.post_id,
                        c.post_title,
                        c.post_teaser,
                        c.ViewCount,
                        c.AvatarImage,
                        c.create_date,
                        c.Tbl_Tags.FirstOrDefault().TagName,
                        c.post_slug
                    })
                           //DISTINCT ĐỂ SAU KHI SELECT ĐỐI TƯỢNG MỚI ĐƯỢC
                           //VÌ THẰNG DƯỚI KHÔNG EQUAL HASHCODE
                           .Distinct().Select(c => new lstPostViewModel
                    {
                        post_id     = c.post_id,
                        post_title  = c.post_title,
                        post_teaser = c.post_teaser,
                        ViewCount   = c.ViewCount,
                        AvatarImage = c.AvatarImage,
                        create_date = c.create_date,
                        tagsname    = c.TagName,
                        slug        = c.post_slug
                    })
                           .ToPagedList(pageIndex, pageSize);
                }
                break;

            case 7:
                post = db.postRepository.AllPosts()
                       .Where(m => m.status)
                       .Where(m => m.post_title.Contains(model.title))
                       .Where(m => m.dynasty.Equals(model.Dynasty.ToString()))
                       .OrderBy(m => m.post_title.Contains(model.title))
                       .Select(m => new lstPostViewModel
                {
                    post_id     = m.post_id,
                    post_title  = m.post_title,
                    post_teaser = m.post_teaser,
                    ViewCount   = m.ViewCount,
                    AvatarImage = m.AvatarImage,
                    create_date = m.create_date,
                    tagsname    = m.Tbl_Tags.FirstOrDefault().TagName,
                    slug        = m.post_slug
                }
                               ).ToPagedList(pageIndex, pageSize);
                break;

            case 8:
                using (DVCPContext conn = db.Context)
                {
                    post = (
                        // instance from context
                        from z in taglist
                        // join list tìm kiếm
                        join a in conn.Tags on z.TagID equals a.TagID
                        // instance from navigation property
                        from b in a.Tbl_POST
                        //join to bring useful data
                        join c in conn.Posts on b.post_id equals c.post_id
                        where c.dynasty == model.Dynasty.ToString()
                        where c.status == true
                        // sắp theo so khớp
                        orderby c.create_date descending
                        select new
                    {
                        c.post_id,
                        c.post_title,
                        c.post_teaser,
                        c.ViewCount,
                        c.AvatarImage,
                        c.create_date,
                        c.Tbl_Tags.FirstOrDefault().TagName,
                        c.post_slug
                    })
                           //DISTINCT ĐỂ SAU KHI SELECT ĐỐI TƯỢNG MỚI ĐƯỢC
                           //VÌ THẰNG DƯỚI KHÔNG EQUAL HASHCODE
                           .Distinct().Select(c => new lstPostViewModel
                    {
                        post_id     = c.post_id,
                        post_title  = c.post_title,
                        post_teaser = c.post_teaser,
                        ViewCount   = c.ViewCount,
                        AvatarImage = c.AvatarImage,
                        create_date = c.create_date,
                        tagsname    = c.TagName,
                        slug        = c.post_slug
                    })
                           .ToPagedList(pageIndex, pageSize);
                }
                break;
            }

            return(View(post));
        }
Beispiel #7
0
 public TagRepository(DVCPContext context)
 {
     this.entity = context;
 }
Beispiel #8
0
 public HotPostRepository(DVCPContext context)
 {
     this.entity = context;
 }
Beispiel #9
0
 public UnitOfWork(DVCPContext _context)
 {
     this.context = _context;
 }
Beispiel #10
0
 public SeriesRepository(DVCPContext context)
 {
     this.entity = context;
 }