Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "PageId,Name,PContent,Recap,Link,Image,ParentId,Pos")] Page page)
        {
            if (ModelState.IsValid)
            {
                page.Link = "/Tin-tuc/" + ClearWordRepository.NoVNeseLower(page.Name) + "-" + page.PageId;
                page.Link = page.Link.Replace("?", "");
                if (Request.Files.Count != 0)
                {
                    if (Request.Files[0].FileName.Contains(".jpg") || Request.Files[0].FileName.Contains(".png") ||
                        Request.Files[0].FileName.Contains(".gif"))
                    {
                        string pathToSaveimage = Server.MapPath("/Storedata/news/" + page.PageId);//Phần vị trí lưu File .
                        CreateFolder(pathToSaveimage);
                        string filename = Path.GetFileName(Request.Files[0].FileName);
                        Request.Files[0].SaveAs(Path.Combine(pathToSaveimage, filename));


                        page.Image = "Storedata/news/" + page.PageId + "/" + filename;
                    }
                }

                db.Entry(page).State = EntityState.Modified;

                db.SaveChanges();
                if (page.PageId == db.Pages.First().PageId)
                {
                    return(Redirect("/Admin/News/Edit/" + page.PageId));
                }
                return(RedirectToAction("Index"));
            }
            return(View(page));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "PageId,Name,PContent,Recap,Link,Image,ParentId,Pos")] Page page)
        {
            if (ModelState.IsValid)
            {
                var url = ClearWordRepository.NoVNeseLower(page.Name).Replace("?", "");
                db.Pages.Add(page);
                db.SaveChanges();
                page.Link = "/Tin-tuc/" + url + "-" + page.PageId;

                if (Request.Files[0].ContentLength != 0)
                {
                    if (Request.Files[0].FileName.Contains(".jpg") || Request.Files[0].FileName.Contains(".png") ||
                        Request.Files[0].FileName.Contains(".gif"))
                    {
                        string pathToSaveimage = Server.MapPath("/Storedata/news/" + page.PageId);//Phần vị trí lưu File .
                        CreateFolder(pathToSaveimage);
                        string filename = Path.GetFileName(Request.Files[0].FileName);
                        Request.Files[0].SaveAs(Path.Combine(pathToSaveimage, filename));

                        var update = db.Pages.ToList().Where(p => p.PageId == page.PageId).First();
                        update.Image = "Storedata/news/" + page.PageId + "/" + filename;
                    }
                }

                db.SaveChanges();

                return(RedirectToAction("Index", new { newId = page.ParentId }));
            }

            return(View(page));
        }
Ejemplo n.º 3
0
        public ActionResult About(Page page)
        {
            if (ModelState.IsValid)
            {
                page.Link = "/Tin-tuc/" + ClearWordRepository.NoVNeseLower(page.Name) + "-" + page.PageId;
                if (page.PageId != 0)
                {
                    if (Request.Files[0].ContentLength != 0)
                    {
                        if (Request.Files[0].FileName.Contains(".jpg") || Request.Files[0].FileName.Contains(".png") ||
                            Request.Files[0].FileName.Contains(".gif"))
                        {
                            string pathToSaveimage = Server.MapPath("/Storedata/news/" + page.PageId);//Phần vị trí lưu File .
                            CreateFolder(pathToSaveimage);
                            string filename = Path.GetFileName(Request.Files[0].FileName);
                            Request.Files[0].SaveAs(Path.Combine(pathToSaveimage, filename));

                            page.Image = "Storedata/news/" + page.PageId + "/" + filename;
                            db.SaveChanges();
                        }
                    }
                    db.Entry(page).State = EntityState.Modified;

                    db.SaveChanges();
                }
                else
                {
                    db.Pages.Add(page);
                    db.SaveChanges();


                    if (Request.Files[0].ContentLength != 0)
                    {
                        if (Request.Files[0].FileName.Contains(".jpg") || Request.Files[0].FileName.Contains(".png") ||
                            Request.Files[0].FileName.Contains(".gif"))
                        {
                            string pathToSaveimage = Server.MapPath("/Storedata/news/" + page.PageId);//Phần vị trí lưu File .
                            CreateFolder(pathToSaveimage);
                            string filename = Path.GetFileName(Request.Files[0].FileName);
                            Request.Files[0].SaveAs(Path.Combine(pathToSaveimage, filename));

                            var update = db.Pages.ToList().Where(p => p.PageId == page.PageId).First();
                            update.Image = "Storedata/news/" + page.PageId + "/" + filename;
                            db.SaveChanges();
                        }
                    }
                }



                return(RedirectToAction("Index"));
            }

            return(View(page));
        }