protected void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         BLOG rec = DALBlog.Get(Int32.Parse(Request.QueryString["ID"]));
         if (rec != null)
         {
             DALBlog.Delete(rec.ID);
         }
         ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ClosePage", "CloseModal(true);", true);
         NotificationAdd(NotificationType.success, "Kayıt Silindi.");
     }
     catch (Exception ex)
     {
         if (ex is SqlException)
         {
             if ((ex as SqlException).Number == 547)
             {
                 NotificationAdd(NotificationType.error, "Kayıt başka yerlerde kullanıdı.");
             }
         }
         else
         {
             throw ex;
         }
     }
 }
Exemple #2
0
        protected void rptrBlog_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "Down":
            {
                BLOG self  = DALBlog.Get(Int32.Parse(e.CommandArgument.ToString()));
                BLOG upper = DALBlog.GetBySort(self.SORT + 1);
                self.SORT++;
                upper.SORT--;
                DALBlog.Update(self);
                DALBlog.Update(upper);
                fillBlog();
                break;
            }

            case "Up":
            {
                BLOG self  = DALBlog.Get(Int32.Parse(e.CommandArgument.ToString()));
                BLOG upper = DALBlog.GetBySort(self.SORT - 1);
                self.SORT--;
                upper.SORT++;
                DALBlog.Update(self);
                DALBlog.Update(upper);
                fillBlog();
                break;
            }
            }
        }
Exemple #3
0
 public IActionResult Add(BLOG blog)
 {
     if (blog.Id == 0)
     {
         var Type = _CategoryDAL.GetOne(int.Parse(blog.CategoryTypeId));
         if (Type != null)
         {
             blog.CategoryTypeName = Type.CName;
         }
         blog.Content_Md = blog.Content;
         blog.Remark     = "";
         blog.BlogId     = Guid.NewGuid().ToString();
         blog.UserID     = "100";
         _BlogDAL.Add(blog);
     }
     else
     {
         blog.Content_Md = blog.Content;
         var Type = _CategoryDAL.GetOne(int.Parse(blog.CategoryTypeId));
         if (Type != null)
         {
             blog.CategoryTypeName = Type.CName;
         }
         blog.Content_Md = blog.Content;
         _BlogDAL.Update(blog);
     }
     return(Redirect("/Admin/Home/Default"));
 }
Exemple #4
0
        public Blog UpdateBlog(Blog blog)
        {
            var resultSP = DB.UpdateBlog(blog.blogId, blog.blogCategory, blog.blogName, blog.blogPublisher, blog.blogContent, blog.blogDate, blog.blogMainPictureLink).Select(b => new Blog
            {
                blogId              = b.blogId,
                blogCategory        = b.blogCategory,
                blogName            = b.blogName,
                blogPublisher       = b.blogPublisher,
                blogContent         = b.blogContent,
                blogDate            = b.blogDate,
                blogMainPictureLink = b.blogMainPictureLink
            });

            if (GlobalVariable.queryType == 0)
            {
                BLOG blo = DB.BLOGs.Where(b => b.blogId == blog.blogId).SingleOrDefault();
                if (blo == null)
                {
                    return(null);
                }
                blo.blogId              = blog.blogId;
                blo.blogCategory        = blog.blogCategory;
                blo.blogName            = blog.blogName;
                blo.blogPublisher       = blog.blogPublisher;
                blo.blogContent         = blog.blogContent;
                blo.blogDate            = blog.blogDate;
                blo.blogMainPictureLink = blog.blogMainPictureLink;
                DB.SaveChanges();
                return(GetBlogById(blog.blogId));
            }
            else
            {
                return(resultSP.SingleOrDefault());
            }
        }
Exemple #5
0
        public Blog AddBlog(Blog blog)
        {
            var resultSP = DB.PostBlog(blog.blogCategory, blog.blogName, blog.blogPublisher, blog.blogContent, blog.blogDate, blog.blogMainPictureLink).Select(b => new Blog
            {
                blogId              = b.blogId,
                blogCategory        = b.blogCategory,
                blogName            = b.blogName,
                blogPublisher       = b.blogPublisher,
                blogContent         = b.blogContent,
                blogDate            = b.blogDate,
                blogMainPictureLink = b.blogMainPictureLink
            });

            if (GlobalVariable.queryType == 0)
            {
                BLOG blo = new BLOG
                {
                    blogCategory        = blog.blogCategory,
                    blogName            = blog.blogName,
                    blogPublisher       = blog.blogPublisher,
                    blogContent         = blog.blogContent,
                    blogDate            = blog.blogDate,
                    blogMainPictureLink = blog.blogMainPictureLink
                };

                DB.BLOGs.Add(blo);
                DB.SaveChanges();
                return(GetBlogById(blo.blogId));
            }
            else
            {
                return(resultSP.SingleOrDefault());
            }
        }
Exemple #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            BLOG bLOG = db.BLOGs.Find(id);

            db.BLOGs.Remove(bLOG);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void InitializePage()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                RECid = Convert.ToInt16(Request.QueryString["ID"]);
                BLOG item = DALBlog.Get(RECid);
                if (item != null)
                {
                    if (string.IsNullOrEmpty(item.IMAGE))
                    {
                        tdImage.Visible = true;
                    }
                    else
                    {
                        tdImage.Visible        = true;
                        tdImagePreview.Visible = true;
                    }

                    imgImage.ImageUrl = Functions.SITEURL.PathAndQuery + "Admin/assets/images/" + item.IMAGE + "_s.jpg";
                    imgImage.Width    = new Unit(GetPrameterValue("SLIDERADMINWIDTH"));
                    imgImage.Height   = new Unit(GetPrameterValue("SLIDERADMINHEIGHT"));
                    if (drpCatergori.Items.Count >= 1)
                    {
                        drpCatergori.SelectedValue = item.CATEGORIESID.ToString();
                    }
                    txtVideo.Text        = item.VIDEOCODE;
                    txtAlt.Text          = item.ALT;
                    hdnDescription.Value = Server.HtmlDecode(item.MAINTEXT);
                    txtTitle.Text        = item.TITLE;
                    chkActive.Checked    = item.ISACTIVE;
                    btnDelete.Visible    = true;
                    if (!string.IsNullOrEmpty(item.VIDEOCODE))
                    {
                        item.ISIMAGE   = false;
                        item.ISVIDEO   = true;
                        item.ISARTICLE = false;
                    }
                    else if (!string.IsNullOrEmpty(item.IMAGE))
                    {
                        item.ISIMAGE   = true;
                        item.ISVIDEO   = false;
                        item.ISARTICLE = false;
                    }
                    else
                    {
                        item.ISIMAGE   = false;
                        item.ISVIDEO   = false;
                        item.ISARTICLE = true;
                    }
                    btnSave.Text = "Güncelle";
                }
            }
            else
            {
                tdImage.Visible = true;
            }
        }
Exemple #8
0
 public ActionResult Edit([Bind(Include = "BLOG_ID,BLOG_TITLE,BLOG_TEXT,BLOG_AUTHOR")] BLOG bLOG)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bLOG).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bLOG));
 }
Exemple #9
0
 /// <summary>
 /// 更新博客内容
 /// </summary>
 /// <param name="blog"></param>
 /// <returns></returns>
 public bool Update(BLOG blog)
 {
     using (var _connection = ConnectionFactory.GetOpenConnection(this.ConnStr))
     {
         if (_connection.Execute("UPDATE [Blog] SET [Title] = @Title ,[Content] = @Content,[Content_Md] = @Content_Md,[CategoryTypeId]=@CategoryTypeId,[CategoryTypeName]=@CategoryTypeName ,[Remark] = @Remark, [Visit] =@Visit WHERE Id=@Id", blog) > 0)
         {
             return(true);
         }
         return(false);
     }
 }
Exemple #10
0
        // GET: Blog
        public ActionResult NhapBlog(BLOG blog)
        {
            NGUOIDUNG nd = (NGUOIDUNG)Session["NguoiDung"];

            blog.NGAYDANG    = DateTime.Now;
            blog.MANGUOIDUNG = nd.MANGUOIDUNG;
            db.BLOGs.Add(blog);
            db.SaveChanges();
            //return Redirect("/TrangChu/Index");
            return(Redirect(Request.UrlReferrer.ToString()));
        }
Exemple #11
0
 /// <summary>
 /// 添加博客
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public bool Add(BLOG entity)
 {
     using (var _connection = ConnectionFactory.GetOpenConnection(this.ConnStr))
     {
         if (_connection.Execute("insert into Blog(Title,Content,Content_Md,CategoryTypeId,CategoryTypeName, UserID, Remark, BlogId,Visit)values(@Title, @Content, @Content_Md, @CategoryTypeId,@CategoryTypeName, @UserID, @Remark, @BlogId,0)", entity) > 0)
         {
             return(true);
         }
         return(false);
     }
 }
Exemple #12
0
        public ActionResult Create([Bind(Include = "BLOG_ID,BLOG_TITLE,BLOG_TEXT,BLOG_AUTHOR")] BLOG bLOG)
        {
            if (ModelState.IsValid)
            {
                db.BLOGs.Add(bLOG);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bLOG));
        }
Exemple #13
0
        public IActionResult Add(int?Id)
        {
            ViewBag.CategoryList = _CategoryDAL.GetList();
            var Blog = new BLOG();

            if (Id != null)
            {
                Blog = _BlogDAL.GetOne(Id.Value);
            }
            return(View(Blog));
        }
        public IActionResult Create(BLOG blog)
        {
            if (ModelState.IsValid)
            {
                _context.BLOG.Add(blog);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(blog));
        }
Exemple #15
0
        public ActionResult SuaBlog(int id)
        {
            BLOG blog = db.BLOGs.SingleOrDefault(n => n.MaBlog == id);

            if (blog == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            //Dua du lieu vao DropdownList
            ViewBag.MaNV = new SelectList(db.NHANVIENs.ToList().OrderBy(n => n.TenNV), "MaNV", "TenNV");
            return(View(blog));
        }
Exemple #16
0
        public ActionResult ChiTietBlog(int id)
        {
            //Lay ra doi tuong Blog
            BLOG blog = db.BLOGs.SingleOrDefault(n => n.MaBlog == id);

            ViewBag.MaBlog = blog.MaBlog;
            if (blog == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(blog));
        }
Exemple #17
0
 public ActionResult Posts(BLOG bg)
 {
     if (bg.BLOG_ID == 0)
     {
         using (DatabasModel db = new DatabasModel())
         {
             db.BLOGs.Add(bg);
             db.SaveChanges();
             return(Json(new { success = true, message = "Blog has been post" }, JsonRequestBehavior.AllowGet));
         }
     }
     return(View());
 }
Exemple #18
0
        // GET: BLOGs/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BLOG bLOG = db.BLOGs.Find(id);

            if (bLOG == null)
            {
                return(HttpNotFound());
            }
            return(View(bLOG));
        }
Exemple #19
0
        // GET: admin/BLOGs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BLOG bLOG = db.BLOGs.Find(id);

            if (bLOG == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID_USERS = new SelectList(db.USERS, "ID_USERS", "USERNAME", bLOG.ID_USERS);
            return(View(bLOG));
        }
Exemple #20
0
        public ActionResult XoaBlog(int id)
        {
            BLOG blog = db.BLOGs.SingleOrDefault(n => n.MaBlog == id);

            ViewBag.MaBlog = blog.MaBlog;
            if (blog == null)
            {
                Response.StatusCode = 404;
                return(null);
            }

            //ViewBag.ThongBao = "Đã xảy ra lỗi trong quá trình xóa, vui lòng thử lại!";


            return(View(blog));
        }
Exemple #21
0
        public ActionResult ThemMoiBlog(BLOG blog, HttpPostedFileBase fileUpload)
        {
            ViewBag.MaNV = new SelectList(db.NHANVIENs.ToList().OrderBy(n => n.TenNV), "MaNV", "TenNV");
            try
            {
                if (fileUpload == null)
                {
                    ViewBag.ThongBao = "Vui lòng chọn ảnh mô tả Blog";
                    return(View());
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        //Luu ten file
                        var fileName = DateTime.Now.ToString("yyyymmddMMss") + "-" + Path.GetFileName(fileUpload.FileName);
                        //Luu duong dan cua file
                        var path = Path.Combine(Server.MapPath("~/images"), fileName);
                        //Kiem tra hinh anh ton tai chua
                        if (System.IO.File.Exists(path))
                        {
                            ViewBag.ThongBao = "Hình ảnh đã tồn tại, vui lòng chọn hình khác.";
                        }
                        else
                        {
                            //Luu hinh anh vao duong dan
                            fileUpload.SaveAs(path);
                        }
                        blog.Hinhanh = fileName;
                        db.BLOGs.InsertOnSubmit(blog);
                        db.SubmitChanges();
                    }
                    return(RedirectToAction("ThemMoiBlog"));
                }
            }
            catch (Exception ex)
            {
                ViewBag.ThongBao = "Đã xảy ra lỗi trong quá trình tạo mới Blog, vui lòng thử lại!";
            }

            return(View());
        }
Exemple #22
0
 public IActionResult ShowBlogDetails(int?Id)
 {
     ViewBag.CategoryList = _CATEGORYDAL.GetList();
     ViewBag.BlogDAL      = _BlogDAL;
     if (Id == null)
     {
         return(Content("找不到该条博客数据!"));
     }
     else
     {
         BLOG bLOG = _BlogDAL.GetOne(Id.Value);
         if (bLOG == null)
         {
             return(Content("找不到该条博客数据!"));
         }
         bLOG.Visit += 1;
         _BlogDAL.Update(bLOG);
         return(View(bLOG));
     }
 }
Exemple #23
0
        public int DeleteBlog(int blogId)
        {
            var resultSP = DB.DeleteBlog(blogId);

            if (GlobalVariable.queryType == 0)
            {
                BLOG blo = DB.BLOGs.Where(b => b.blogId == blogId).SingleOrDefault();
                DB.BLOGs.Attach(blo);
                if (blo == null)
                {
                    return(0);
                }
                DB.BLOGs.Remove(blo);
                DB.SaveChanges();
                return(1);
            }
            else
            {
                return(resultSP);
            }
        }
 public static void TransToBlogData()
 {
     for (int i = 0; i < Info.items.Count; i++)
     {
         BLOG     a    = Info.items [i];
         BlogData blog = new BlogData();
         blog.id     = a.blog_id;
         blog.userId = a.user_id;
         blog.path   = a.blog_path;
         blog.order  = a.order;
         List <BlogData> blogs;
         if (ZoneManager.Instance.id2Blog.TryGetValue(a.user_id, out blogs))
         {
         }
         else
         {
             blogs = new List <BlogData> ();
             ZoneManager.Instance.id2Blog.Add(a.user_id, blogs);
         }
         blogs.Add(blog);
     }
 }
Exemple #25
0
        public ActionResult Create([Bind(Include = "ID_BLOG,TITLE,IMG,DETAIL,DATEBEGIN,META,ORDER,LINK,HIDE,ID_USERS,DESCRIPTION")] BLOG bLOG, HttpPostedFileBase img)
        {
            try
            {
                var path     = "";
                var filename = "";
                var date     = DateTime.Now.ToString(); // get datetime at present
                date = date.Replace(" ", "_");          // replace space by _
                date = date.Replace("/", "_");          // replace / by _
                date = date.Replace(":", "_");          // replace : by _
                date = date + "_";                      // insert character _ in the end of string

                if (ModelState.IsValid)
                {
                    if (img != null)
                    {
                        filename = date + img.FileName;
                        path     = Path.Combine(Server.MapPath("~/Content/upload/img/news"), filename);
                        img.SaveAs(path);
                        bLOG.IMG = filename;
                    }
                    bLOG.DATEBEGIN = DateTime.Now;
                    bLOG.META      = Help.Functions.ConvertToUnSign(bLOG.TITLE);
                    db.BLOGs.Add(bLOG);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DbEntityValidationException e)
            {
                throw e;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            ViewBag.ID_USERS = new SelectList(db.USERS, "ID_USERS", "USERNAME", bLOG.ID_USERS);
            return(View(bLOG));
        }
Exemple #26
0
        public ActionResult XacNhanXoa(int id)
        {
            try {
                BLOG blog = db.BLOGs.SingleOrDefault(n => n.MaBlog == id);
                ViewBag.MaBlog = blog.MaBlog;
                if (blog == null)
                {
                    Response.StatusCode = 404;
                    return(null);
                }
                db.BLOGs.DeleteOnSubmit(blog);
                db.SubmitChanges();


                //ViewBag.ThongBao = "Đã xảy ra lỗi trong quá trình xóa, vui lòng thử lại!";
            }
            catch
            {
                ViewBag.ThongBao = "Đã xảy ra lỗi trong quá trình xóa, vui lòng thử lại!";
            }
            return(RedirectToAction("BlogAdmin"));
        }
Exemple #27
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (ValidateItem())
     {
         BLOG rec = new BLOG();
         if (RECid > 0)
         {
             rec = DALBlog.Get(RECid);
             if (!string.IsNullOrEmpty(IMAGE))
             {
                 rec.IMAGE = IMAGE;
             }
             if (!string.IsNullOrEmpty(txtVideo.Text))
             {
                 rec.ISIMAGE   = false;
                 rec.ISVIDEO   = true;
                 rec.ISARTICLE = false;
             }
             else if (!string.IsNullOrEmpty(rec.IMAGE))
             {
                 rec.ISIMAGE   = true;
                 rec.ISVIDEO   = false;
                 rec.ISARTICLE = false;
             }
             else
             {
                 rec.ISIMAGE   = false;
                 rec.ISVIDEO   = false;
                 rec.ISARTICLE = true;
             }
             if (drpCatergori.Items.Count >= 1)
             {
                 rec.CATEGORIESID = Int32.Parse(drpCatergori.SelectedItem.Value);
             }
             else
             {
                 rec.CATEGORIESID = -1;
             }
             rec.EDITOR    = ONLINEUSER.NAME;
             rec.ALT       = txtAlt.Text;
             rec.ISACTIVE  = chkActive.Checked;
             rec.MAINTEXT  = Server.HtmlEncode(hdnDescription.Value);
             rec.TITLE     = txtTitle.Text;
             rec.URLSEO    = Code.Helper.SEOUrl(txtTitle.Text);
             rec.VIDEOCODE = txtVideo.Text;
             DALBlog.Update(rec);
         }
         else
         {
             if (!string.IsNullOrEmpty(txtVideo.Text))
             {
                 rec.ISIMAGE   = false;
                 rec.ISVIDEO   = true;
                 rec.ISARTICLE = false;
             }
             else if (!string.IsNullOrEmpty(IMAGE))
             {
                 rec.ISIMAGE   = true;
                 rec.ISVIDEO   = false;
                 rec.ISARTICLE = false;
             }
             else
             {
                 rec.ISIMAGE   = false;
                 rec.ISVIDEO   = false;
                 rec.ISARTICLE = true;
             }
             if (drpCatergori.Items.Count >= 1)
             {
                 rec.CATEGORIESID = Int32.Parse(drpCatergori.SelectedItem.Value);
             }
             else
             {
                 rec.CATEGORIESID = -1;
             }
             rec.VIDEOCODE = txtVideo.Text;
             rec.EDITOR    = ONLINEUSER.NAME;
             rec.IMAGE     = IMAGE;
             rec.SORT      = Convert.ToInt16(DALBlog.GetLastSort() + 1);
             rec.ALT       = txtAlt.Text;
             rec.ISACTIVE  = chkActive.Checked;
             rec.MAINTEXT  = Server.HtmlEncode(hdnDescription.Value);
             rec.TITLE     = txtTitle.Text;
             rec.URLSEO    = Code.Helper.SEOUrl(txtTitle.Text);
             rec.DATE      = DateTime.Now;
             DALBlog.Insert(rec);
         }
         ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ClosePage", "CloseModal(true);", true);
         btnDelete.Visible = false;
         btnCancel.Visible = false;
     }
 }