Пример #1
0
        public ActionResult Create(StaticPageModel pageModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    User user = _authenService.GetAuthenticatedUser();

                    StaticPage page = pageModel.ToEntity();
                    page.Created    = DateTime.Now;
                    page.Modified   = page.Created;
                    page.CreatedBy  = user.Id;
                    page.ModifiedBy = page.CreatedBy;

                    _pageService.AddPage(page);

                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    ErrorNotification(e.ToString());
                }
            }
            else
            {
                AddModelStateErrors();
            }
            Title = "Thêm mới trang tĩnh";
            ViewData["ToolbarTitle"] = Title;
            return(View());
        }
Пример #2
0
        /// <summary>
        /// Gets the page with the given slug.
        /// </summary>
        /// <param name="slug">The slug</param>
        /// <returns>The page</returns>
        public async Task <StaticPageModel> GetPageAsync(string slug)
        {
            if (!string.IsNullOrWhiteSpace(slug))
            {
                var key = _baseSlug + slug;

                if (Sitemap.Routes.TryGetValue(key, out var page))
                {
                    var model = new StaticPageModel
                    {
                        Title        = page.Title,
                        Slug         = page.Slug,
                        Path         = page.Path,
                        Redirect     = page.Redirect,
                        Created      = page.Created,
                        LastModified = page.LastModified
                    };

                    if (string.IsNullOrWhiteSpace(model.Redirect))
                    {
                        var file = new FileInfo(page.Path);

                        using (var sr = new StreamReader(file.OpenRead()))
                        {
                            model.Markdown = await sr.ReadToEndAsync();

                            model.Body = App.Markdown.Transform(model.Markdown);
                        }
                    }
                    return(model);
                }
            }
            return(null);
        }
        public ActionResult About()
        {
            var oModel = new StaticPageModel();

            oModel.OStaticPage = DAL.News.StaticPages.StaticPagesGet(new StaticPages {
                Id = 2
            }).Results.FirstOrDefault();

            var getMembers = DAL.News.TeamMembers.TeamMembersGet(new TeamMembers {
                Page = Convert.ToInt32(1), RowPerPage = 4, SortCol = "Id", IsWithUs = true
            });

            if (getMembers.HasResult)
            {
                oModel.LstTeamMembers = getMembers.Results;
            }
            var getStatics = DAL.News.StaticData.GetStaticData(new StaticData {
                Type = 1
            });

            if (getStatics.HasResult)
            {
                oModel.LstOurGoals = getStatics.Results;
            }
            getStatics = DAL.News.StaticData.GetStaticData(new StaticData {
                Type = 3
            });
            if (getStatics.HasResult)
            {
                oModel.OurMethodology = getStatics.Results;
            }
            return(View(oModel));
        }
Пример #4
0
        public virtual ActionResult Save(StaticPageModel staticPageModel)
        {
            if (staticPageModel.StaticPageId > 0)
            {
                if (!ModelState.IsValid)
                {
                    var entity = Repository.GetById(staticPageModel.StaticPageId);
                    var model  = new StaticPageModel()
                    {
                        Content      = HttpUtility.HtmlDecode(entity.Content),
                        Description  = entity.Description,
                        StaticPageId = entity.StaticPageId
                    };
                    return(View("Edit", model));
                }

                var staticPageEntity = Repository.GetById(staticPageModel.StaticPageId);
                staticPageEntity.Content     = staticPageModel.Content;
                staticPageEntity.Description = staticPageModel.Description;
                using (UnitOfWork)
                {
                    Repository.Update(staticPageEntity);
                }
            }

            //Save success
            this.SetSuccessNotification(string.Format("{0} đã được lưu thành công.", "Bài viết"));
            return(RedirectToAction("Index", new { area = "Administrator" }));
        }
Пример #5
0
        public ActionResult Contact()
        {
            var oModel = new StaticPageModel();

            oModel.OStaticPage = _db.StaticPages.First(x => x.Id == 3);
            return(View(oModel));
        }
        public ActionResult Contact()
        {
            var oModel = new StaticPageModel();

            oModel.OStaticPage = DAL.News.StaticPages.StaticPagesGet(new StaticPages {
                Id = 3
            }).Results.FirstOrDefault();
            return(View(oModel));
        }
Пример #7
0
 public ActionResult Edit([Bind(Include = "Id,Content,Title")] StaticPageModel staticPage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(StaticPageModel.ToEntity(staticPage)).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(staticPage));
 }
Пример #8
0
        public ActionResult Create([Bind(Include = "Id,Content,Title")] StaticPageModel staticPage)
        {
            if (ModelState.IsValid)
            {
                db.StaticPages.Add(StaticPageModel.ToEntity(staticPage));
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(staticPage));
        }
Пример #9
0
        // GET: View
        public ActionResult View(int id)
        {
            StaticPage staticPage = db.StaticPages.Find(id);

            if (staticPage == null)
            {
                return(HttpNotFound());
            }

            return(View(StaticPageModel.FromEntity(staticPage)));
        }
Пример #10
0
        public virtual ActionResult Edit(int id)
        {
            var entity = Repository.GetById(id);
            var model  = new StaticPageModel()
            {
                Content      = HttpUtility.HtmlDecode(entity.Content),
                Description  = entity.Description,
                StaticPageId = entity.StaticPageId
            };

            return(View("Edit", model));
        }
Пример #11
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StaticPage staticPage = db.StaticPages.Find(id);

            if (staticPage == null)
            {
                return(HttpNotFound());
            }
            return(View(StaticPageModel.FromEntity(staticPage)));
        }
        public ActionResult Index()
        {
            var oModel = new StaticPageModel();

            oModel.OStaticPage = DAL.News.StaticPages.StaticPagesGet(new StaticPages {
                Id = 1
            }).Results.FirstOrDefault();
            var getNews = DAL.News.News.NewsGet(new News {
                CategoryId = Convert.ToInt32(1), Page = Convert.ToInt32(1), RowPerPage = 4, SortCol = "PublishDate"
            }, 0);

            if (getNews.HasResult)
            {
                oModel.LstNews = getNews.Results;
            }
            var getSocials = DAL.News.SocialNW.GetSocialNW(new SocialNW {
                IsList = true
            });

            if (getSocials.HasResult)
            {
                oModel.LstSocials = getSocials.Results;
            }
            var getStatics = DAL.News.StaticData.GetStaticData(new StaticData {
                Type = 1
            });

            if (getStatics.HasResult)
            {
                oModel.LstOurGoals = getStatics.Results;
            }
            getStatics = DAL.News.StaticData.GetStaticData(new StaticData {
                Type = 2
            });
            if (getStatics.HasResult)
            {
                oModel.LstStatistics = getStatics.Results.Where(x => x.Status == true).ToList();
            }
            return(View(oModel));
        }
Пример #13
0
        public ActionResult Edit(StaticPageModel pageModel)
        {
            string command = Request.Form["submit"].ToString();

            switch (command)
            {
            case "Save":
            case "SaveAndContinueEdit":
                if (ModelState.IsValid)
                {
                    try
                    {
                        StaticPage page = _pageService.GetPageById(pageModel.Id);
                        if (page == null)
                        {
                            ErrorNotification("Không tìm thấy trang tĩnh nào thỏa mãn");
                            return(RedirectToAction("Index"));
                        }
                        User user = _authenService.GetAuthenticatedUser();

                        page.Title           = pageModel.Title;
                        page.SeoUrl          = pageModel.SeoUrl;
                        page.MetaDescription = pageModel.MetaDescription;
                        page.MetaKeyword     = pageModel.MetaKeyword;
                        page.IsActive        = pageModel.IsActive;
                        page.Content         = pageModel.Content;
                        page.Modified        = DateTime.Now;
                        page.ModifiedBy      = user.Id;

                        _pageService.UpdatePage(page);

                        SuccessNotification("Cập nhật thông tin trang tĩnh thành công");

                        if (command == "SaveAndContinueEdit")
                        {
                            Title = "Chỉnh sửa thông tin trang tĩnh: " + page.Title;
                            //return View(pageModel);
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (Exception e)
                    {
                        Title = "Chỉnh sửa thông tin trang tĩnh";
                        ErrorNotification(e.ToString());
                    }
                }
                else
                {
                    AddModelStateErrors();
                }

                break;

            case "Delete":
                return(RedirectToAction("Delete", new { id = pageModel.Id }));

            default:
                ErrorNotification("Không rõ phương thức submit dữ liệu");
                return(RedirectToAction("Index"));
            }

            ViewData["ToolbarTitle"] = Title;
            return(View(pageModel));
        }
Пример #14
0
 public ActionResult Index()
 {
     return(View(StaticPageModel.FromEntity(db.StaticPages.AsQueryable())));
 }