Пример #1
0
 public int PUpdatePost(string id, string title, string slug, string cate, string tag, string content, string Intro)
 {
     using (var ctx = new BlogCouponEntities())
     {
         int idP = 0;
         if (int.TryParse(id, out idP) == false)
         {
             return(0);
         }
         var post = ctx.Posts.Where(c => c.ID == idP).FirstOrDefault();
         if (post == null)
         {
             return(0);
         }
         post.Title      = title;
         post.Slug       = slug;
         post.Update     = DateTime.Now;
         post.Tag        = tag;
         post.CategoryID = int.Parse(cate);
         post.Content    = content;
         post.Intro      = Intro;
         var checkSlug = ctx.Posts.Where(c => c.Slug == slug).FirstOrDefault();
         ctx.Entry(post).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
         //if (checkSlug != null)
         //{
         //    post.Slug = post.Slug + "-" + post.ID;
         //}
         //ctx.Entry(post).State = System.Data.Entity.EntityState.Modified;
         //ctx.SaveChanges();
         return(1);
     }
 }
Пример #2
0
 public ActionResult ProcessComment(string postid, string relyto, string level, string name, string email, string web, string content)
 {
     using (var ctx = new BlogCouponEntities())
     {
         var comment = new Comment();
         comment.CDate     = DateTime.Now;
         comment.CommentTo = int.Parse(relyto);
         comment.Level     = int.Parse(level);
         comment.Name      = name;
         comment.PostID    = int.Parse(postid);
         comment.Web       = web;
         comment.Content   = content;
         comment.Flag      = 0;
         try
         {
             ctx.Comments.Add(comment);
             ctx.SaveChanges();
             return(Json("1", JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             return(Json(ex.Message, JsonRequestBehavior.AllowGet));
         }
     }
 }
Пример #3
0
        public int PUpdateImage(List <Dictionary <string, string> > lst)
        {
            using (var ctx = new BlogCouponEntities())
            {
                foreach (var item in lst)
                {
                    int    id  = int.Parse(item["ID"].ToString());
                    string url = item["Url"].ToString();

                    var post = ctx.Posts.Where(c => c.ID == id).FirstOrDefault();
                    if (post == null || post.ImgThumb == url)
                    {
                        continue;
                    }
                    post.ImgThumb         = url;
                    ctx.Entry(post).State = System.Data.Entity.EntityState.Modified;
                }
                try
                {
                    ctx.SaveChanges();
                    return(1);
                }
                catch (Exception)
                {
                    return(-1);
                }
            }
        }
Пример #4
0
        public int PUpdateCoupon(int IDCoupon, string Title, string PostID, string Link, string Branch,
                                 string Type, string DateEnd, string Code, string Note, string Percent)
        {
            using (var ctx = new BlogCouponEntities())
            {
                int tmp    = 0;
                var coupon = ctx.Coupons.Where(c => c.ID == IDCoupon).FirstOrDefault();
                if (coupon == null)
                {
                    return(0);
                }

                coupon.Title = Title;
                //coupon.Cate = int.TryParse(frm["Cate"].ToString(),out tmp)?tmp:0;
                coupon.PostID  = int.TryParse(PostID, out tmp) ? tmp : 0;
                coupon.Branch  = Branch;
                coupon.Note    = Note;
                coupon.SellOff = int.TryParse(Percent, out tmp) ? tmp : 0;
                coupon.Type    = int.Parse(Type);

                coupon.Code = Code;
                coupon.Link = Link;

                string[] temp = DateEnd.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);


                coupon.DateEnd          = temp.Length == 0 ? DateTime.Now : new DateTime(int.Parse(temp[2]), int.Parse(temp[1]), int.Parse(temp[0]));
                ctx.Entry(coupon).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }
            return(1);
        }
Пример #5
0
        public ActionResult AddCoupon(FormCollection frm)
        {
            using (var ctx = new BlogCouponEntities())
            {
                int tmp    = 0;
                var coupon = new Coupon();
                coupon.Title = frm["Title"].ToString();
                //coupon.Cate = int.TryParse(frm["Cate"].ToString(),out tmp)?tmp:0;
                coupon.PostID  = int.TryParse(frm["Cate"].ToString(), out tmp) ? tmp : 0;
                coupon.Branch  = frm["Branch"].ToString();
                coupon.Note    = frm["Note"].ToString();
                coupon.SellOff = int.TryParse(frm["Percent"].ToString(), out tmp) ? tmp : 0;
                coupon.Type    = int.Parse(frm["Type"].ToString());


                coupon.Code = frm["Code"].ToString();

                coupon.Link = frm["Link"].ToString();

                //DateTime tmpDate;
                //coupon.DateEnd = DateTime.TryParse(frm["DateEnd"].ToString(), null, System.Globalization.DateTimeStyles.AssumeUniversal, out tmpDate) == true ? tmpDate : DateTime.Today;
                string[] temp = frm["DateEnd"].ToString().Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                coupon.DateEnd = temp.Length == 0 ? DateTime.Now : new DateTime(int.Parse(temp[2]), int.Parse(temp[1]), int.Parse(temp[0]));
                ctx.Coupons.Add(coupon);
                ctx.SaveChanges();
            }
            TempData["AddSuccess"] = "Đăng Coupon thành công!";
            return(Redirect("/Admin/AddCoupon"));
        }
Пример #6
0
 // GET: Admin/GetCategories
 public ActionResult GetCategories()
 {
     using (var ctx = new BlogCouponEntities())
     {
         return(Json(ctx.Categories.ToList(), JsonRequestBehavior.AllowGet));
     }
 }
Пример #7
0
        public int AddCategories(string ParentID, string Name, string Slug)
        {
            using (var ctx = new BlogCouponEntities())
            {
                Category cate = new Category();
                cate.Name = Name;
                cate.Slug = Slug;
                if (!String.IsNullOrEmpty(ParentID))
                {
                    cate.ParentID = int.Parse(ParentID);

                    var group = ctx.Categories.Where(c => c.ID == cate.ParentID).FirstOrDefault();
                    cate.GroupName = group.Name;
                }
                try
                {
                    ctx.Categories.Add(cate);
                    ctx.SaveChanges();
                    return(1);
                }
                catch (Exception)
                {
                    return(0);
                }
            }
        }
Пример #8
0
        public ActionResult AddPost(FormCollection frm)
        {
            using (var ctx = new BlogCouponEntities())
            {
                var post = new Post();
                post.Title = frm["Title"].ToString();
                string slug  = frm["Slug"].ToString();
                string intro = frm["Intro"].ToString();

                var checkSlug = ctx.Posts.Where(c => c.Slug == slug).FirstOrDefault();


                post.Slug       = frm["Slug"].ToString();
                post.Content    = frm["Content"].ToString();
                post.CategoryID = int.Parse(frm["CategoryID"].ToString());
                post.Tag        = frm["Tag"].ToString();
                post.CreateDate = DateTime.Now;
                post.Flag       = 1;
                post.Intro      = intro;
                ctx.Posts.Add(post);
                ctx.SaveChanges();
                if (checkSlug != null)
                {
                    post.Slug = post.Slug + "-" + post.ID;
                }
                ctx.Entry(post).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }
            TempData["AddSuccess"] = "Đăng bài thành công!";
            return(RedirectToAction("AddPost", "Admin"));
        }
Пример #9
0
 public void GetCommentChild(int commentID, int postID)
 {
     using (var ctx = new BlogCouponEntities())
     {
         var commentChild = ctx.Comments.Where(c => c.CommentTo == commentID && c.PostID == postID).ToList();
         Session["CommentChild"] = commentChild;
     }
 }
Пример #10
0
 public ActionResult MenuChild(int id)
 {
     using (var ctx = new BlogCouponEntities())
     {
         var lst = ctx.Categories.Where(c => c.ParentID == id).OrderByDescending(c => c.ID).ToList();
         return(PartialView(lst));
     }
 }
Пример #11
0
 public ActionResult GetMoreComment(int id, int postid)
 {
     using (var ctx = new BlogCouponEntities())
     {
         var comment = ctx.Comments.Where(c => c.CommentTo == id && c.PostID == postid).ToList();
         return(Json(comment, JsonRequestBehavior.AllowGet));
     }
 }
Пример #12
0
        // GET: Home
        public ActionResult Index()
        {
            using (var ctx = new BlogCouponEntities())
            {
                var posthost = ctx.Posts.Where(c => c.Flag == 1).OrderByDescending(c => c.CreateDate).ToList();

                return(View(posthost));
            }
        }
Пример #13
0
 public ActionResult ListPost(int type = 1)
 {
     //type=1 postnew
     //type=2
     using (var ctx = new BlogCouponEntities())
     {
         var postnew = ctx.Posts.Where(c => c.Flag == 1).OrderByDescending(c => c.CreateDate).Take(6).ToList();
         return(PartialView(postnew));
     }
 }
Пример #14
0
 public int CheckCommentChild(int?id, int post)
 {
     if (id.HasValue == false)
     {
         return(0);
     }
     using (var ctx = new BlogCouponEntities())
     {
         var comment = ctx.Comments.Where(c => c.CommentTo == id.Value && c.PostID == post).ToList();
         return(comment.Count);
     }
 }
Пример #15
0
 public ActionResult GetCoupon(int?id)
 {
     if (!id.HasValue)
     {
         return(Json(null, JsonRequestBehavior.AllowGet));
     }
     using (var ctx = new BlogCouponEntities())
     {
         var post = ctx.Coupons.Where(c => c.ID == id).FirstOrDefault();
         return(Json(post, JsonRequestBehavior.AllowGet));
     }
 }
Пример #16
0
 public ActionResult CateSlugPage(string slug)
 {
     using (var ctx = new BlogCouponEntities())
     {
         var cate = ctx.Categories.Where(c => c.Slug == slug).FirstOrDefault();
         if (cate == null)
         {
             ViewBag.NotFound = "Không tìm thấy dữ liệu";
             return(View());
         }
         var posts = ctx.Posts.Where(c => c.CategoryID == cate.ID).ToList();
         return(View(posts));
     }
 }
Пример #17
0
 public ActionResult GetListPostsCombobox()
 {
     using (var ctx = new BlogCouponEntities())
     {
         DataTable ds = new DataTable();
         using (SqlConnection connection = new SqlConnection(ctx.Database.Connection.ConnectionString))
         {
             using (SqlCommand cmd = new SqlCommand("SELECT p.ID,P.Title FROM Posts p WHERE p.Flag=1 ", connection))
             {
                 SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                 adapter.Fill(ds);
             }
         }
         var lst = GetTableRows(ds);
         return(Json(lst, JsonRequestBehavior.AllowGet));
         // return Json(ctx.Posts.Where(c => c.Flag == 1).ToList(), JsonRequestBehavior.AllowGet);
     }
 }
Пример #18
0
        public ActionResult RenderPage(string slug)
        {
            using (var ctx = new BlogCouponEntities())
            {
                var post = ctx.Posts.Where(c => c.Slug == slug).FirstOrDefault();
                if (post == null)
                {
                    ViewBag.NotFound = "Không tìm thấy dữ liệu";
                    return(View());
                }
                var coupons = ctx.Coupons.Where(c => c.PostID == post.ID).ToList();

                var Comments = ctx.Comments.Where(c => c.Level == 1 && c.PostID == post.ID).ToList();

                ViewBag.Coupons  = coupons;
                ViewBag.Comments = Comments;
                return(View(post));
            }
        }
Пример #19
0
 public int DeleteBlog(int?ID)
 {
     if (!ID.HasValue)
     {
         return(0);
     }
     using (var ctx = new BlogCouponEntities())
     {
         var post = ctx.Posts.Where(c => c.ID == ID).FirstOrDefault();
         if (post == null)
         {
             return(0);
         }
         post.Flag             = 0;
         ctx.Entry(post).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
         return(1);
     }
 }
Пример #20
0
        public ActionResult GetListPosts()
        {
            using (var ctx = new BlogCouponEntities())
            {
                //  var ret = ctx.Database.SqlQuery<object>("SELECT p.*,c.Name 'CateName' FROM Posts p LEFT JOIN Categories c ON p.CategoryID=c.ID").ToDictionary<string,object>();

                DataTable ds = new DataTable();
                using (SqlConnection connection = new SqlConnection(ctx.Database.Connection.ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("SELECT p.*,c.Name 'CateName' FROM Posts p LEFT JOIN Categories c ON p.CategoryID=c.ID WHERE p.Flag=1", connection))
                    {
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        adapter.Fill(ds);
                    }
                }
                var lst = GetTableRows(ds);
                return(Json(lst, JsonRequestBehavior.AllowGet));
            }
        }
Пример #21
0
        public ActionResult GetCbbCategories()
        {
            using (var ctx = new BlogCouponEntities())
            {
                //List<Category> lst = new List<Category>() { new Category() { ID = 0, Name = "Không" } };
                var lst    = ctx.Categories.Where(c => c.GroupName == null).ToList();
                var result = new List <Category>();
                foreach (var item in lst)
                {
                    result.Add(item);
                    var child = ctx.Categories.Where(c => c.ParentID == item.ID).ToList();
                    if (child != null)
                    {
                        result.AddRange(child);
                    }
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Пример #22
0
        public ActionResult GetListCoupon()
        {
            using (var ctx = new BlogCouponEntities())
            {
                //  var ret = ctx.Database.SqlQuery<object>("SELECT p.*,c.Name 'CateName' FROM Posts p LEFT JOIN Categories c ON p.CategoryID=c.ID").ToDictionary<string,object>();

                DataTable ds = new DataTable();
                using (SqlConnection connection = new SqlConnection(ctx.Database.Connection.ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("SELECT p.*,CASE WHEN p.Type=1 THEN N'Mã giảm giá' ELSE 'Link Aff' END as 'TypeName',c.Title 'PostName' " +
                                                           "FROM Coupons p LEFT JOIN Posts c ON p.PostID=c.ID ", connection))
                    {
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        adapter.Fill(ds);
                    }
                }
                var lst = GetTableRows(ds);
                return(Json(lst, JsonRequestBehavior.AllowGet));
            }
        }
Пример #23
0
 public int UpdateCategories(int?ID, string Name, string Slug)
 {
     if (!ID.HasValue)
     {
         return(0);
     }
     using (var ctx = new BlogCouponEntities())
     {
         var cate = ctx.Categories.Where(c => c.ID == ID).FirstOrDefault();
         if (cate == null)
         {
             return(0);
         }
         cate.Name             = Name;
         cate.Slug             = Slug;
         ctx.Entry(cate).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
         return(1);
     }
 }
Пример #24
0
 public ActionResult Menu()
 {
     using (var ctx = new BlogCouponEntities())
     {
         var lst = ctx.Categories.Where(c => c.ParentID == null).OrderBy(c => c.ID).ToList();
         for (int i = 0; i < lst.Count; i++)
         {
             int id    = lst[i].ID;
             var child = ctx.Categories.Where(c => c.ParentID == id).ToList();
             if (child.Count > 0)
             {
                 lst[i].HasChild = true;
             }
             else
             {
                 lst[i].HasChild = false;
             }
         }
         return(PartialView(lst));
     }
 }
Пример #25
0
        public int DeleteCategories(int?ID)
        {
            if (!ID.HasValue)
            {
                return(0);
            }
            using (var ctx = new BlogCouponEntities())
            {
                var cate = ctx.Categories.Where(c => c.ID == ID).FirstOrDefault();
                if (cate == null)
                {
                    return(0);
                }
                ctx.Categories.Remove(cate);
                var lstChild = ctx.Categories.Where(c => c.ParentID == ID).ToList();
                if (lstChild != null)
                {
                    ctx.Categories.RemoveRange(lstChild);
                }

                ctx.SaveChanges();
                return(1);
            }
        }