Exemplo n.º 1
0
        //
        // GET: /Posts/

        public ActionResult Index(int?Id)
        {
            int id = 0;

            if (Id != 0 && Id != null)
            {
                id = (int)Id;

                tbl_Post           p          = PostProvider.GetPost(id);
                List <tbl_Comment> c          = CommentProvider.GetAllCommentByPostId(id);
                PostModel          _PostModel = new PostModel {
                    Id = p.Id, ContentMsg = p.ContentMsg, Title = p.Title, UpdatedBy = p.UpdatedBy
                };
                List <CommentModel> _commentModel = (from temp in c select new CommentModel {
                    Id = temp.Id, CommentText = temp.CommentText, PostId = temp.PostId, CommentedBy = temp.CommentedBy
                }).ToList();
                PostViewModel Model = new PostViewModel();
                Model.Comments = _commentModel;
                Model.Post     = _PostModel;
                return(View(Model));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        public static string Update(int ID, string Title, string Content, string Image, int Featured, int CategoryID, int Status, string PostSlug, string ModifiedBy, DateTime ModifiedDate)
        {
            using (var dbe = new inventorymanagementEntities())
            {
                tbl_Post ui = dbe.tbl_Post.Where(a => a.ID == ID).SingleOrDefault();
                if (ui != null)
                {
                    ui.Title        = Title;
                    ui.Content      = Content;
                    ui.Image        = Image;
                    ui.Featured     = Featured;
                    ui.CategoryID   = CategoryID;
                    ui.Status       = Status;
                    ui.ModifiedBy   = ModifiedBy;
                    ui.ModifiedDate = ModifiedDate;
                    ui.Slug         = checkSlug(Slug.ConvertToSlug(PostSlug != "" ? PostSlug : Title), ui.ID);

                    int kq = dbe.SaveChanges();
                    return(ui.ID.ToString());
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 3
0
        public static tbl_Post Insert(tbl_Post data)
        {
            using (var con = new inventorymanagementEntities())
            {
                con.tbl_Post.Add(data);
                con.SaveChanges();

                return(data);
            }
        }
Exemplo n.º 4
0
 public void addData()
 {
     for (int i = 1; i <= 100; i++)
     {
         var newItem = new tbl_Post
         {
             Title = "Mohammad",
             Body  = "bensaeed"
         };
         _db.tbl_Post.Add(newItem);
     }
     _db.SaveChanges();
 }
Exemplo n.º 5
0
 public static tbl_Post GetByID(int ID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_Post ai = dbe.tbl_Post.Where(a => a.ID == ID).SingleOrDefault();
         if (ai != null)
         {
             return(ai);
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 6
0
 public static string Delete(int ID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_Post ui = dbe.tbl_Post.Where(o => o.ID == ID).FirstOrDefault();
         if (ui != null)
         {
             dbe.tbl_Post.Remove(ui);
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 7
0
 public static string UpdateImage(int ID, string Image)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_Post ui = dbe.tbl_Post.Where(a => a.ID == ID).SingleOrDefault();
         if (ui != null)
         {
             ui.Image = Image;
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 8
0
 public static string updateWebPublish(int id, bool value)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_Post ui = dbe.tbl_Post.Where(a => a.ID == id).SingleOrDefault();
         if (ui != null)
         {
             ui.WebPublish = value;
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 9
0
 public static string Insert(string Title, string Content, string Image, int Featured, int CategoryID, int Status, string CreatedBy, DateTime CreatedDate)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_Post ui = new tbl_Post();
         ui.Title       = Title;
         ui.Content     = Content;
         ui.Image       = Image;
         ui.Featured    = Featured;
         ui.CategoryID  = CategoryID;
         ui.Status      = Status;
         ui.CreatedBy   = CreatedBy;
         ui.CreatedDate = CreatedDate;
         dbe.tbl_Post.Add(ui);
         dbe.SaveChanges();
         int kq = ui.ID;
         return(kq.ToString());
     }
 }
Exemplo n.º 10
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                string Title    = txtTitle.Text.Trim();
                string PostSlug = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Content  = pContent.Content.ToString();

                var newPost = new tbl_Post()
                {
                    Title        = Title,
                    Content      = Content,
                    Image        = "",
                    Featured     = ddlFeatured.SelectedValue.ToInt(),
                    CategoryID   = cateID,
                    Status       = 1,
                    CreatedBy    = acc.Username,
                    CreatedDate  = currentDate,
                    ModifiedBy   = acc.Username,
                    ModifiedDate = currentDate,
                    WebPublish   = false,
                    WebUpdate    = currentDate,
                    Slug         = PostSlug
                };

                var post = PostController.Insert(newPost);

                if (post != null)
                {
                    //Phần thêm ảnh đại diện
                    string path  = "/uploads/images/posts/";
                    string Image = "";
                    if (ProductThumbnailImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in ProductThumbnailImage.UploadedFiles)
                        {
                            var o = path + "post-" + post.ID + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Image = o;
                            }
                            catch { }
                        }
                    }

                    string updateImage = PostController.UpdateImage(post.ID, Image);

                    //Phần thêm thư viện ảnh
                    string IMG = "";
                    if (hinhDaiDien.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in hinhDaiDien.UploadedFiles)
                        {
                            var o = path + "post-" + post.ID + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                PostImageController.Insert(post.ID, IMG, username, currentDate);
                            }
                            catch { }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo bài viết thành công", "s", true, "redirectTo(" + post.ID + ")", Page);
                }
            }
        }
Exemplo n.º 11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                int    CategoryID   = ddlCategory.Value.ToInt();
                var    category     = PostPublicCategoryController.GetByID(CategoryID);
                string CategorySlug = category.Slug;
                string Title        = txtTitle.Text.Trim();
                string Slugs        = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Link         = txtLink.Text.Trim();
                string Content      = pContent.Content.ToString();
                string Summary      = HttpUtility.HtmlDecode(pSummary.Content.ToString());
                string Action       = ddlAction.SelectedValue.ToString();
                string ActionValue  = "";
                if (Action == "view_more")
                {
                    ActionValue = Slugs;
                }
                else if (Action == "show_web")
                {
                    ActionValue = Link;
                }
                bool AtHome   = ddlAtHome.SelectedValue.ToBool();
                bool IsPolicy = false;

                var newPostPublic = new PostPublic()
                {
                    CategoryID   = CategoryID,
                    CategorySlug = CategorySlug,
                    Title        = Title,
                    Thumbnail    = "",
                    Summary      = Summary,
                    Content      = Content,
                    Action       = Action,
                    ActionValue  = ActionValue,
                    AtHome       = AtHome,
                    IsPolicy     = IsPolicy,
                    CreatedDate  = currentDate,
                    CreatedBy    = acc.Username,
                    ModifiedDate = currentDate,
                    ModifiedBy   = acc.Username
                };

                var post = PostPublicController.Insert(newPostPublic);

                if (post != null)
                {
                    // Thêm ảnh đại diện
                    string path  = "/uploads/images/posts/";
                    string Image = "";
                    if (PostPublicThumbnailImage.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles)
                        {
                            var o = path + "post-app-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                Image = o;
                            }
                            catch { }
                        }
                    }
                    string updateImage = PostPublicController.UpdateImage(post.ID, Image);

                    // Thêm thư viện ảnh
                    string IMG = "";
                    if (ImageGallery.UploadedFiles.Count > 0)
                    {
                        foreach (UploadedFile f in ImageGallery.UploadedFiles)
                        {
                            var o = path + "post-app-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                            try
                            {
                                f.SaveAs(Server.MapPath(o));
                                IMG = o;
                                PostPublicImageController.Insert(post.ID, IMG, username, currentDate);
                            }
                            catch { }
                        }
                    }

                    // Copy bài viết vào hệ thống gốc
                    if (ddlCopyToSystem.SelectedValue == "True" && post.Action == "view_more")
                    {
                        var categorySystem = PostCategoryController.GetByName(category.Name);
                        var postSystem     = new tbl_Post()
                        {
                            Title        = post.Title,
                            Content      = post.Content,
                            Image        = Image,
                            Featured     = 1,
                            CategoryID   = categorySystem != null ? categorySystem.ID : 0,
                            Status       = 1,
                            CreatedBy    = post.CreatedBy,
                            CreatedDate  = post.CreatedDate,
                            ModifiedBy   = post.ModifiedBy,
                            ModifiedDate = post.ModifiedDate,
                            WebPublish   = true,
                            WebUpdate    = post.CreatedDate,
                            Slug         = post.ActionValue
                        };

                        PostController.Insert(postSystem);

                        // Copy image
                        if (postSystem != null)
                        {
                            var imagePostPublic = PostPublicImageController.GetByPostID(post.ID);
                            if (imagePostPublic.Count > 0)
                            {
                                foreach (var item in imagePostPublic)
                                {
                                    PostImageController.Insert(postSystem.ID, item.Image, postSystem.CreatedBy, DateTime.Now);
                                }
                            }
                        }
                    }


                    // Tạo phiên bản cho wordpress
                    if (!String.IsNullOrEmpty(hdfPostVariants.Value))
                    {
                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                        var variants = serializer.Deserialize <List <PostClone> >(hdfPostVariants.Value);
                        if (variants != null)
                        {
                            foreach (var item in variants)
                            {
                                var newPostClone = new PostClone()
                                {
                                    PostPublicID = post.ID,
                                    Web          = item.Web,
                                    PostWebID    = 0,
                                    CategoryID   = post.CategoryID,
                                    CategoryName = category.Name,
                                    Title        = !String.IsNullOrEmpty(item.Title) ? item.Title : post.Title,
                                    Summary      = post.Summary,
                                    Content      = post.Content,
                                    Thumbnail    = Image,
                                    CreatedDate  = post.CreatedDate,
                                    CreatedBy    = acc.Username,
                                    ModifiedDate = post.ModifiedDate,
                                    ModifiedBy   = acc.Username
                                };

                                PostCloneController.Insert(newPostClone);
                            }
                        }
                    }

                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo bài viết thành công", "s", true, "redirectTo(" + post.ID.ToString() + ")", Page);
                }
            }
        }