Пример #1
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"));
        }
Пример #2
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);
        }
Пример #3
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"));
        }
Пример #4
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);
                }
            }
        }
Пример #5
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);
     }
 }
Пример #6
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);
                }
            }
        }
Пример #7
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));
         }
     }
 }
Пример #8
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);
     }
 }
Пример #9
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);
     }
 }
Пример #10
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);
            }
        }