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); }
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); } } }
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); } }
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")); }
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); } }
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); } }