public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            object         model;
            ViewResultBase result = filterContext.Result as ViewResultBase;

            if (result != null)
            {
                model = result.Model;
            }
            else
            {
                JsonResult jsonResult = filterContext.Result as JsonResult;
                if (jsonResult == null)
                {
                    return;
                }
                model = jsonResult.Data;
            }
            if (model == null)
            {
                return;
            }
            PageVm pageVm = model as PageVm;

            if (pageVm == null)
            {
                FormatterResolver.ApplyFormatting <EntityLocation>(model, EntityLocation.Search);
                return;
            }
            FormatterResolver.ApplyFormatting <PageType>(model, pageVm.PageType);
        }
Example #2
0
        public ActionResult EditPage(PageVm model)
        {
            //check model state
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (Db db = new Db())
            {
                //GET page id
                int id = model.Id;

                //initialiaze Slug
                string slug = "home";

                //Get the page
                PageDTO dto = db.Pages.Find(id);

                //DTO the title
                dto.Title = model.Title;

                //check for slug and set ifnecessary
                if (model.Slug != "home")
                {
                    if (string.IsNullOrWhiteSpace(model.Slug))
                    {
                        slug = model.Title.Replace(" ", "-").ToLower();
                    }
                    else
                    {
                        slug = model.Slug.Replace(" ", "-").ToLower();
                    }
                }

                //make sure title and slug are unique
                if (db.Pages.Where(x => x.Id != id).Any(x => x.Title == model.Title) ||
                    db.Pages.Where(x => x.Id != id).Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "Title and slug already exists.");
                    return(View(model));
                }

                //DTO d rest
                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSidebar = model.HasSidebar;

                //save changes
                db.SaveChanges();
            }

            //set TempData message
            TempData["SM"] = "Page edited sucessfully!";


            //Redirect
            return(RedirectToAction("EditPage"));
        }
        public ActionResult EditPage(PageVm model)
        {
            //check model state
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (db DB = new db())
            {
                //Get page ID
                int id = model.ID;

                //Declare slug
                string slug = "home";

                //Get the page
                DTO dto = DB.Pages.Find(id);

                //DTO the title
                dto.Title = model.Title;

                //Check for slug and set it if need be
                if (model.Slug != "home")
                {
                    if (string.IsNullOrWhiteSpace(model.Slug))
                    {
                        slug = model.Title.Replace(" ", "-").ToLower();
                    }
                    else
                    {
                        slug = model.Slug.Replace(" ", "-").ToLower();
                    }
                }
                //Check if title and slug are unique
                if (DB.Pages.Where(x => x.ID != id).Any(x => x.Title == model.Title) ||
                    DB.Pages.Where(x => x.ID != id).Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "That title or slug already exist.");
                    return(View(model));
                }

                //DTO the rest
                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSideBar = model.HasSideBar;

                //Save the DTO
                DB.SaveChanges();
            }

            //Set TempData message
            TempData["SM"] = "You have edited the page!";

            //Redirect
            return(RedirectToAction("EditPage"));
        }
Example #4
0
        public PageVm MapPageToPageVm(StoryTeller.Core.Pages.Page page)
        {
            var pageVm = new PageVm();

            var pgActionTask = _gameActionVmFactory.MapGameActionToVm(page.actions);

            pageVm.Actions = pgActionTask.ToList();

            return(pageVm);
        }
        public ActionResult AddPage(PageVm model)
        {
            //Check model state
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (db DB = new db())
            {
                //Declare slug
                string slug;

                //Init DTO
                DTO dto = new DTO();

                //DTO Title
                dto.Title = model.Title;

                //Check for and set slug if need be
                if (string.IsNullOrWhiteSpace(model.Slug))
                {
                    slug = model.Title.Replace(" ", "-").ToLower();
                }
                else
                {
                    slug = model.Slug.Replace(" ", "-").ToLower();
                }

                //Make sure title and slug is unique
                if (DB.Pages.Any(x => x.Title == model.Title) || DB.Pages.Any(x => x.Slug == model.Slug))
                {
                    ModelState.AddModelError("", "That Title or slug already exists.");
                    return(View(model));
                }

                //DTO the rest
                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSideBar = model.HasSideBar;
                dto.Sorting    = 100;


                //Save DTO
                DB.Pages.Add(dto);
                DB.SaveChanges();
            }

            //Set TempData message
            TempData["SM"] = "You have added a new page!";

            //Redirect
            return(RedirectToAction("AddPage"));
        }
Example #6
0
        // POST: Admin/Pages/AddPage
        public ActionResult AddPage(PageVm model)
        {
            //check model state
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (Db db = new Db())
            {
                //Declare slug
                string slug;

                //init pageDTO
                PageDTO dto = new PageDTO();

                //DTO Title
                dto.Title = model.Title;

                //check for and slug if necessary
                if (string.IsNullOrWhiteSpace(model.Slug))
                {
                    slug = model.Title.Replace(" ", "-").ToLower();
                }
                else
                {
                    slug = model.Slug.Replace(" ", "-").ToLower();
                }
                // To Make sure slug and title are unique
                if (db.Pages.Any(x => x.Title == model.Title) || db.Pages.Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "Title or slug already exist.");
                    return(View(model));
                }
                //DTO the rest
                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSidebar = model.HasSidebar;
                dto.Sorting    = 100; //since the pages wont be more than hundred, whenever you add a page it will be the last page

                //save DTO
                db.Pages.Add(dto);
                db.SaveChanges();
            }

            // Set TempData message, just like a toast message
            TempData["SM"] = "Page added successfully!";

            //Redirect
            return(RedirectToAction("AddPage"));
        }
Example #7
0
        protected void BindContentData(PageVm pageVm)
        {
            _gameContentManager.BindImage(pageVm.Image);
            _gameContentManager.BindTitle(pageVm.Title);

            _gameContentManager.BindContentText(pageVm.Content);

            Actions.Clear();

            foreach (var item in pageVm.Actions)
            {
                Actions.Add(item);
            }
        }
Example #8
0
        public ActionResult EditPage(int id)
        {
            PageVm model;

            using (db)
            {
                PageDto dto = db.Pages.Find(id);
                if (dto == null)
                {
                    return(Content("The page doesn't exist."));
                }
                model = new PageVm(dto);
            }
            return(View(model));
        }
Example #9
0
        public async Task <PageVm> MapDtoToPageVmAsync(PageDto dto,
                                                       IEnumerable <PageActionDto> pageActions,
                                                       IEnumerable <PageContentDto> pageContent)
        {
            var pagevm = new PageVm();

            var pgActionsTask = await _gameActionVmFactory.MapGameActionDtoToVmAsync(pageActions);

            pagevm.Actions = pgActionsTask.ToList();

            var pgContentTask = await _textSpanFactory.MapContentDtoToSpanAsync(pageContent);

            pagevm.Content = pgContentTask.ToList();

            return(pagevm);
        }
Example #10
0
        public ActionResult EditPage(PageVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (CmsDbContext db = new CmsDbContext())
            {
                var slug = "Home";
                int id   = model.Id;

                PageDto dto = db.Pages.Find(id);
                dto.Title = model.Title;

                if (model.Slug != "Home")
                {
                    if (string.IsNullOrWhiteSpace(model.Slug))
                    {
                        slug = model.Title.Replace(" ", "-").ToLower();
                    }
                    else
                    {
                        slug = model.Slug.Replace(" ", "-").ToLower();
                    }
                }

                if (db.Pages.Where(x => x.Id != id).Any(x => x.Title == model.Title) ||
                    db.Pages.Where(x => x.Id != id).Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "This slug or title already exist.");
                    return(View(model));
                }

                dto.Slug       = slug;
                dto.Body       = model.Body;
                dto.HasSideBar = model.HasSideBar;
                dto.Sorting    = 100;

                if (db.SaveChanges() > 0)
                {
                    TempData["SuccessMessage"] = "You have Edited this page!";
                    return(RedirectToAction("EditPage"));
                }
            }
            TempData["SuccessMessage"] = "There is an error while updating this page";
            return(View(model));
        }
Example #11
0
        // GET: Index/{page}
        public ActionResult Index(string page = "")
        {
            //Get/Set page slug
            if (page == "")
            {
                page = "home";
            }

            //Declare model and DTO
            PageVm model;
            DTO    dto;

            //check if page exists

            using (db DB = new db())
            {
                if (!DB.Pages.Any(x => x.Slug.Equals(page)))
                {
                    return(RedirectToAction("Index", new { page = "" }));
                }
            }

            //Get page DTO
            using (db DB = new db())
            {
                dto = DB.Pages.Where(x => x.Slug == page).FirstOrDefault();
            }

            //Set page title
            ViewBag.PageTitle = dto.Title;

            //check for sidebar
            if (dto.HasSideBar == true)
            {
                ViewBag.Sidebar = "Yes";
            }
            else
            {
                ViewBag.Sidebar = "No";
            }

            //Init model
            model = new PageVm(dto);

            return(View(model));
        }
Example #12
0
        public async Task <PageVm> MapTranslatedPageDtoToPageVmAsync(TranslatedPageDto translatedPageDto)
        {
            return(await Task.Run(() =>
            {
                var pageVm = new PageVm();
                pageVm.Title = translatedPageDto.Title;
                pageVm.Image = translatedPageDto.Image;

                pageVm.Content = new List <Span>();

                var pageActions = _gameActionVmFactory.MapGameActionToVm(translatedPageDto.PageActions);
                pageVm.Actions = pageActions.ToList();

                var pageContents = _textSpanFactory.MapTextSpanToXamarinSpan(translatedPageDto.TranslatedContent);
                pageVm.Content = pageContents.ToList();

                return pageVm;
            }));
        }
Example #13
0
        public IActionResult PageDetail(long id)
        {
            var page = _pageRepository.Query().FirstOrDefault(x => x.Id == id);

            if (page == null)
            {
                return(NotFound());
            }

            var model = new PageVm
            {
                Name            = _contentLocalizationService.GetLocalizedProperty(page, nameof(page.Name), page.Name),
                Body            = _contentLocalizationService.GetLocalizedProperty(page, nameof(page.Body), page.Body),
                MetaTitle       = page.MetaTitle,
                MetaKeywords    = page.MetaKeywords,
                MetaDescription = page.MetaDescription
            };

            return(View(model));
        }
Example #14
0
        public ActionResult AddPage(PageVm pageVm)
        {
            using (CmsDbContext db = new CmsDbContext())
            {
                string  slug;
                PageDto pageDto = new PageDto();

                pageDto.Title = pageVm.Title;

                if (!ModelState.IsValid)
                {
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(pageVm.Slug))
                {
                    slug = pageVm.Title.Replace(" ", "-").ToLower();
                }
                else
                {
                    slug = pageVm.Slug.Replace(" ", "-").ToLower();
                }

                if (db.Pages.Any(x => x.Title == pageVm.Title) || db.Pages.Any(x => x.Slug == slug))
                {
                    ModelState.AddModelError("", "The title already exist");
                    return(View());
                }

                pageDto.Slug       = slug;
                pageDto.Body       = pageVm.Body;
                pageDto.HasSideBar = pageVm.HasSideBar;
                pageDto.Sorting    = 100;

                db.Pages.Add(pageDto);
                db.SaveChanges();

                TempData["SuccessMessage"] = "You have added a new Page";
                return(RedirectToAction("AddPage"));
            }
        }
Example #15
0
        //GET: Admin/Pages/PageDetails/id
        public ActionResult PageDetails(int id)
        {
            //Declare pageVm
            PageVm model;

            using (Db db = new Db())
            {
                //get the page
                PageDTO dto = db.Pages.Find(id);

                //confirm page exists
                if (dto == null)
                {
                    return(Content("The page does not exist"));
                }
                //initialise pages
                model = new PageVm(dto);
            }
            //return view with model
            return(View(model));
        }
Example #16
0
        public ActionResult EditPage(int id)
        {
            //Declare pageVm
            PageVm model;

            using (Db db = new Db())
            {
                //Get the page
                PageDTO dto = db.Pages.Find(id);

                //confirm if page exist
                if (dto == null)
                {
                    return(Content("Page does not exist"));
                }

                //initialise pageVm with the help of d constructor
                model = new PageVm(dto);
            }
            //Return view with model
            return(View(model));
        }
        // GET: Admin/PageDetails
        public ActionResult PageDetails(int id)
        {
            //Declare PageVm
            PageVm model;

            using (db DB = new db())
            {
                //Get the page
                DTO dto = DB.Pages.Find(id);

                //Confirm page exist
                if (dto == null)
                {
                    return(Content("The page does not exist."));
                }

                //Init PageVm
                model = new PageVm(dto);
            }

            return(View(model));
        }
        public ActionResult EditPage(int id)
        {
            //Declare pagevm
            PageVm model;

            using (db DB = new db())
            {
                //Get the page
                DTO dto = DB.Pages.Find(id);

                //confirm page exists
                if (dto == null)
                {
                    return(Content("The page does not exist."));
                }

                //Init pagevm
                model = new PageVm(dto);
            }

            //return view with model
            return(View(model));
        }