public ActionResult Edit(FormCollection collection, int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                string   nameCategory     = collection["namecategory"].ToString();
                string   urlCategory      = collection["urlcategory"].ToString();
                string   parentIdCategory = collection["ParentId"].ToString();
                Category cate             = db.Categories.SingleOrDefault(n => n.Id == id);
                ViewBag.ParentId = new SelectList(db.Categories.Where(n => n.ParentId == null), "Id", "Name", cate.ParentId).ToList();
                cate.Name        = nameCategory;

                if (parentIdCategory == "NULL")
                {
                    cate.ParentId = null;
                }
                else
                {
                    cate.ParentId = Convert.ToInt32(parentIdCategory);
                }

                cate.Url = urlCategory;

                db.SaveChanges();
                return(RedirectToAction("Create"));
            }
        }
예제 #2
0
        public ActionResult Edit(FormCollection collection, int id)
        {
            string   title      = collection["title"].ToString();
            string   summary    = collection["summary"].ToString();
            string   content    = collection["content"].ToString();
            DateTime dateposted = DateTime.Parse(collection["dateposted"].ToString());
            int      authorid   = int.Parse(collection["authorid"].ToString());
            int      posterid   = int.Parse(collection["posterid"].ToString());
            string   avatar     = collection["avatar"].ToString();
            int      categoryid = int.Parse(collection["categoryid"].ToString());
            string   trangthai  = collection["trangthai"].ToString();

            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                News news = db.News.SingleOrDefault(n => n.Id == id);
                news.Title      = title;
                news.Summary    = summary;
                news.Content    = content;
                news.Dateposted = dateposted;
                news.AuthorId   = authorid;
                news.PosterId   = posterid;
                news.Avatar     = avatar;
                news.CategoryId = categoryid;
                news.TrangThai  = trangthai;

                ViewBag.PosterId   = new SelectList(db.Accounts.ToList(), "Id", "Fullname", news.PosterId);
                ViewBag.AuthorId   = new SelectList(db.Authors.ToList(), "Id", "Name", news.AuthorId);
                ViewBag.CategoryId = new SelectList(db.Categories.Where(n => !(n.Url == "" && n.ParentId == null)).ToList(), "Id", "Name", news.CategoryId);
                db.SaveChanges();

                return(RedirectToAction("Create"));
            }
        }
예제 #3
0
 public ActionResult Signin(Account user)
 {
     if (ModelState.IsValid)
     {
         using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
         {
             var ckeckAD = db.Accounts.SingleOrDefault(n => n.Email.Equals(user.Email) && n.Password.Equals(user.Password) && n.Quyen.Equals("Admin"));
             if (ckeckAD != null)
             {
                 Session["Id"]       = ckeckAD.Id.ToString();
                 Session["Fullname"] = ckeckAD.Fullname.ToString();
                 Session["Email"]    = ckeckAD.Email.ToString();
                 Session["Avatar"]   = ckeckAD.Avatar.ToString();
                 return(RedirectToAction("Create", "Categories"));
             }
             var checkUS = db.Accounts.SingleOrDefault(n => n.Email.Equals(user.Email) && n.Password.Equals(user.Password) && n.Quyen.Equals("User") && n.TrangThai.Equals("Hoạt động"));
             if (checkUS != null)
             {
                 Session["Id"]       = checkUS.Id.ToString();
                 Session["Fullname"] = checkUS.Fullname.ToString();
                 return(Redirect("/Home/Index"));
             }
             else
             {
                 ViewBag.tbDangNhap = "Email/Password sai hoặc đã bị khóa";
                 return(View());
             }
         }
     }
     return(View());
 }
예제 #4
0
        public ActionResult Signup(FormCollection collection)
        {
            string fullname     = collection["fullname"].ToString();
            string email        = collection["email"].ToString();
            string password     = collection["password"].ToString();
            string confpassword = collection["confpassword"].ToString();
            string avatar       = collection["avatar"].ToString();
            string trangthai    = "Hoạt động";
            string quyen        = "User";

            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                Account acc        = new Account();
                var     checkEmail = db.Accounts.SingleOrDefault(n => n.Email.Equals(email));
                if (checkEmail == null)
                {
                    acc.Fullname        = fullname;
                    acc.Email           = email;
                    acc.Password        = password;
                    acc.Confirmpassword = confpassword;
                    acc.Avatar          = avatar;
                    acc.TrangThai       = trangthai;
                    acc.Quyen           = quyen;
                    db.Accounts.Add(acc);
                    db.SaveChanges();
                    ViewBag.tbDangKy = acc.Fullname + "  đăng ký thành công!";
                }
                else
                {
                    ViewBag.tbDangKyLoi = email + " đã tồn tại!";
                }
                return(View());
            }
        }
 public ActionResult Create()
 {
     using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
     {
         List <Author> lstAuthor = db.Authors.ToList();
         return(View(lstAuthor));
     }
 }
예제 #6
0
        public ActionResult Delete(int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                News news = db.News.SingleOrDefault(n => n.Id == id);

                db.News.Remove(news);

                db.SaveChanges();

                return(RedirectToAction("Create"));
            }
        }
 public ActionResult Edit(int id)
 {
     using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
     {
         Category cate = db.Categories.SingleOrDefault(n => n.Id == id);
         ViewBag.ParentId = new SelectList(db.Categories.Where(n => n.ParentId == null), "Id", "Name", cate.ParentId).ToList();
         if (cate == null)
         {
             Response.StatusCode = 404;
             return(null);
         }
         return(View(cate));
     }
 }
        public ActionResult Edit(FormCollection collection, int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                string authorName    = collection["authorname"].ToString();
                string authorAddress = collection["authoraddress"].ToString();
                Author aut           = db.Authors.SingleOrDefault(n => n.Id == id);
                aut.Name    = authorName;
                aut.Address = authorAddress;

                db.SaveChanges();
                return(RedirectToAction("Create"));
            }
        }
        public ActionResult Edit(int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                Author aut = db.Authors.SingleOrDefault(n => n.Id == id);
                if (aut == null)
                {
                    Response.StatusCode = 404;
                    return(null);
                }

                return(View(aut));
            }
        }
예제 #10
0
        public ActionResult Delete(int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                //lay doi tuong can xoa
                Author aut = db.Authors.SingleOrDefault(n => n.Id == id);

                // thuc hien xoa doi tuong
                db.Authors.Remove(aut);

                //Thay doi trong csdl
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }
        }
 public ActionResult Create()
 {
     using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
     {
         if (Session["Id"] != null)
         {
             ViewBag.ParentId = new SelectList(db.Categories.Where(n => n.ParentId == null), "Id", "Name").ToList();
             List <Category> lstCategory = db.Categories.ToList();
             return(View(lstCategory));
         }
         else
         {
             return(RedirectToAction("Signin", "Account"));
         }
     }
 }
예제 #12
0
        public ActionResult Edit(int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                News news = db.News.SingleOrDefault(n => n.Id == id);
                if (news == null)
                {
                    Response.StatusCode = 404;
                    return(null);
                }
                ViewBag.PosterId   = new SelectList(db.Accounts.ToList(), "Id", "Fullname", news.PosterId);
                ViewBag.AuthorId   = new SelectList(db.Authors.ToList(), "Id", "Name", news.AuthorId);
                ViewBag.CategoryId = new SelectList(db.Categories.Where(n => !(n.Url == "" && n.ParentId == null)).ToList(), "Id", "Name", news.CategoryId);

                return(View(news));
            }
        }
예제 #13
0
 // POST: //Account/DelAccount/
 public int DelAccount(int id)
 {
     using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
     {
         Account delaccount = db.Accounts.SingleOrDefault(n => n.Id == id);
         if (delaccount != null)
         {
             db.Accounts.Remove(delaccount);
             db.SaveChanges();
             return(id);
         }
         else
         {
             return(-1);
         }
     }
 }
        public ActionResult Search(int?page, string tukhoa)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                ViewBag.TuKhoa = tukhoa;
                List <Category> lstResult  = db.Categories.Where(n => n.Name.Contains(tukhoa)).ToList();
                int             pageNumber = (page ?? 1);
                int             pageSize   = 3;
                if (lstResult.Count == 0)
                {
                    ViewBag.khongtimthay = "Không tìm thấy ";
                }

                ViewBag.timthay = "Đã tìm thấy " + lstResult.Count + "";
                return(View(lstResult.OrderBy(n => n.Name).ToList()));
            }
        }
예제 #15
0
        public ActionResult Search(FormCollection collection, int?page)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                string tukhoa = collection["txtsearch"].ToString();
                ViewBag.TuKhoa = tukhoa;

                List <Author> lstResult  = db.Authors.Where(n => n.Name.Contains(tukhoa)).ToList();
                int           pageNumber = (page ?? 1);
                int           pageSize   = 3;
                if (lstResult.Count == 0)
                {
                    ViewBag.khongtimthay = "Không tìm thấy";
                }
                ViewBag.timthay = "Đã tìm thấy " + lstResult.Count + "";
                return(View(lstResult.OrderBy(n => n.Name).ToList()));
            }
        }
예제 #16
0
 //GET: //Account/LoadAccount
 public JsonResult LoadAccount()
 {
     using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
     {
         var lstAccount = db.Accounts.Select(n => new
         {
             ID           = n.Id,
             FullName     = n.Fullname,
             Email        = n.Email,
             TrangThai    = n.TrangThai,
             Quyen        = n.Quyen,
             PassWord     = n.Password,
             ConfPassWord = n.Confirmpassword,
             Avatar       = n.Avatar
         }).ToList();
         return(Json(new { Account1 = lstAccount }, JsonRequestBehavior.AllowGet));
     }
 }
예제 #17
0
 public string ChangeImage(int id, string avatar)
 {
     using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
     {
         if (id == 0)
         {
             return("Mã không tồn tại");
         }
         News news = db.News.Find(id);
         if (news == null)
         {
             return("Mã không tồn tại");
         }
         news.Avatar = avatar;
         db.SaveChanges();
         return("");
     }
 }
예제 #18
0
        public ActionResult Create(FormCollection collection)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                string authorName    = collection["authorname"].ToString();
                string authorAddress = collection["authoraddress"].ToString();

                Author aut = new Author();
                aut.Name    = authorName;
                aut.Address = authorAddress;

                db.Authors.Add(aut);
                db.SaveChanges();

                List <Author> lstAuthor = db.Authors.ToList();
                return(View(lstAuthor));
            }
        }
예제 #19
0
        public ActionResult Create(int?page)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
                if (Session["Id"] != null)
                {
                    int pageSize   = 3;
                    int pageNumber = (page ?? 1);

                    ViewBag.PosterId   = new SelectList(db.Accounts.ToList(), "Id", "Fullname");
                    ViewBag.AuthorId   = new SelectList(db.Authors.ToList(), "Id", "Name");
                    ViewBag.CategoryId = new SelectList(db.Categories.Where(n => !(n.Url == "" && n.ParentId == null)).ToList(), "Id", "Name");

                    List <News> lstCategory = db.News.ToList();
                    return(View(db.News.ToList().ToPagedList(pageNumber, pageSize)));
                }
                else
                {
                    return(RedirectToAction("Signin", "Account"));
                }
        }
예제 #20
0
        public ActionResult Search(int?page, string tukhoa)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                ViewBag.TuKhoa = tukhoa;
                //
                ViewBag.PosterId   = new SelectList(db.Accounts.ToList(), "Id", "Fullname");
                ViewBag.AuthorId   = new SelectList(db.Authors.ToList(), "Id", "Name");
                ViewBag.CategoryId = new SelectList(db.Categories.ToList(), "Id", "Name");

                List <News> lstResult  = db.News.Where(n => n.Title.Contains(tukhoa) || n.Summary.Contains(tukhoa)).ToList();
                int         pageNumber = (page ?? 1);
                int         pageSize   = 1;
                if (lstResult.Count == 0)
                {
                    ViewBag.searchfalse = "Không tìm thấy ";
                }

                ViewBag.search = "Đã tìm thấy " + lstResult.Count + "";
                return(View(lstResult.OrderBy(n => n.Id).ToPagedList(pageNumber, pageSize)));
            }
        }
예제 #21
0
        public ActionResult Create(FormCollection collection, int?page)
        {
            int pageSize   = 3;
            int pageNumber = (page ?? 1);

            string   title      = collection["title"].ToString();
            string   summary    = collection["summary"].ToString();
            string   content    = collection["content"].ToString();
            DateTime dateposted = DateTime.Parse(collection["dateposted"].ToString());
            int      authorid   = int.Parse(collection["authorid"].ToString());
            int      posterid   = int.Parse(collection["posterid"].ToString());
            string   avatar     = collection["avatar"].ToString();
            string   trangthai  = collection["trangthai"].ToString();
            int      view       = 0;
            int      categoryid = int.Parse(collection["categoryid"].ToString());

            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                ViewBag.PosterId   = new SelectList(db.Accounts.ToList(), "Id", "Fullname");
                ViewBag.AuthorId   = new SelectList(db.Authors.ToList(), "Id", "Name");
                ViewBag.CategoryId = new SelectList(db.Categories.Where(n => !(n.Url == "" && n.ParentId == null)).ToList().ToList(), "Id", "Name");

                News news = new News();
                news.Title      = title;
                news.Summary    = summary;
                news.Content    = content;
                news.Dateposted = dateposted;
                news.AuthorId   = authorid;
                news.PosterId   = posterid;
                news.Avatar     = avatar;
                news.CategoryId = categoryid;
                news.TrangThai  = trangthai;
                news.View       = view;
                db.News.Add(news);
                db.SaveChanges();
                return(View(db.News.ToList().ToPagedList(pageNumber, pageSize)));
            }
        }
        public ActionResult Create(FormCollection collection)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                string   nameCategory     = collection["namecategory"].ToString();
                string   urlCategory      = collection["urlcategory"].ToString();
                string   parentIdCategory = collection["ParentId"].ToString();
                Category cate             = new Category();
                cate.Name = nameCategory;
                if (urlCategory == null)
                {
                    cate.Url = null;
                }
                else
                {
                    cate.Url = urlCategory;
                }

                if (parentIdCategory == "NULL")
                {
                    cate.ParentId = null;
                }
                else
                {
                    cate.ParentId = Convert.ToInt32(parentIdCategory);
                }

                //Them doi tuong vao csdl
                db.Categories.Add(cate);
                //Thuc hien ghi vao csdl
                db.SaveChanges();
                ViewBag.ParentId = new SelectList(db.Categories.Where(n => n.ParentId == null), "Id", "Name").ToList();
                //Lay danh sach chuyen muc trong csdl tra ve view
                List <Category> lstCategory = db.Categories.ToList();
                return(View(lstCategory));
            }
        }
        public ActionResult Delete(int id)
        {
            using (Web_NEWS_MVCEntities db = new Web_NEWS_MVCEntities())
            {
                try
                {
                    //Lấy đối tượng cần xóa
                    Category cate = db.Categories.SingleOrDefault(x => x.Id == id);

                    //Thực hiện xóa đối tượng
                    db.Categories.Remove(cate);

                    //Thực hiện thay đổi trong csdl
                    db.SaveChanges();

                    //Lay danh sach chuyen muc trong csdl tra ve view
                    return(RedirectToAction("Create"));
                }
                catch
                {
                    return(RedirectToAction("Create"));
                }
            }
        }