public JsonResult DeleteRedirect(string id)
        {
            var result = new JsonResult();

            try
            {
                if (String.IsNullOrEmpty(id))
                {
                    return(result);
                }

                var redirectId = Int32.Parse(id);
                var redirect   = Context.Redirects.FirstOrDefault(x => x.RedirectId == redirectId);

                Context.Redirects.Remove(redirect);
                Context.SaveChanges();

                // recycle cache after save
                CachedObjects.GetRedirectsList(true);

                result.Data = new { success = true };
                return(result);
            }
            catch
            {
                result.Data = new { success = false };
                return(result);
            }
        }
        public JsonResult EditRedirect(int id, String source, String destination, Boolean isPermanent, Boolean rootMatching)
        {
            var result = new JsonResult();

            try
            {
                var redirect = Context.Redirects.FirstOrDefault(x => x.RedirectId == id);

                if (redirect != null)
                {
                    redirect.Source       = source;
                    redirect.Destination  = destination;
                    redirect.IsPermanent  = isPermanent;
                    redirect.RootMatching = rootMatching;
                    redirect.DateModified = DateTime.UtcNow;
                    redirect.IsActive     = true;

                    Context.SaveChanges();

                    result.Data = new
                    {
                        id      = redirect.RedirectId,
                        success = true
                    };
                }

                CachedObjects.GetRedirectsList(true);
                return(result);
            }
            catch
            {
                result.Data = new { success = false };
                return(result);
            }
        }
Пример #3
0
 public ActionResult Index()
 {
     return(View(new PluginViewModel
     {
         InstalledPlugins = CachedObjects.GetRegisteredPlugins()
     }));
 }
Пример #4
0
        public ActionResult NewContentPage(string schemaId, string editContentHeading)
        {
            // Create a new Content Page to be passed to the edit content action
            var page = GetDefaultContentPage();

            // If a schema was passed in, we will want to assign that schema id to the newly created page
            // We will also want to copy over html from an existing page that uses that html. That way the user has a consistent editor.
            ApplySchema(page, schemaId);

            Context.ContentPages.Add(page);
            Context.SaveChanges();

            // Update the page title / permalink with the new id we now have
            page.DisplayName = "Page " + page.ContentPageId;
            page.Title       = "Page " + page.ContentPageId;
            page.HTMLContent = ContentUtils.ReplacePageParametersInHtmlContent(page.HTMLUnparsed, page);

            AddNewPageExtension(page);


            Context.SaveChanges();
            CachedObjects.GetCacheContentPages(true);

            // Pass content Heading along if it exists
            object routeParameters = new { id = page.ContentPageId };

            if (!String.IsNullOrEmpty(editContentHeading))
            {
                routeParameters = new { id = page.ContentPageId, schema = schemaId, editContentHeading };
            }

            return(RedirectToAction("EditContent", "Pages", routeParameters));
        }
Пример #5
0
        public async Task <ObservableCollection <ICategoriesItemVM> > LoadItemsFor(string categoryId = null)
        {
            ObservableCollection <ICategoriesItemVM> dataSource = null;

            try
            {
                IEnumerable <Category> categories;

                if (!CachedObjects.ContainsKey(categoryId.IsNullOrEmtpy() ? "null" : categoryId))
                {
                    categories = await CategoriesService.LoadCategories(categoryId);

                    if (!categories.IsNullOrEmpty())
                    {
                        CachedObjects.Add(categoryId.IsNullOrEmtpy() ? "null" : categoryId, categories);
                    }
                }
                else
                {
                    categories = CachedObjects[categoryId.IsNullOrEmtpy() ? "null" : categoryId].Cast <Category>();
                }

                dataSource = new ObservableCollection <ICategoriesItemVM>(categories.Select(c => SetupItem(c)));
            }
            catch (ConnectionException ex)
            {
                OnConnectionException(ex);
            }
            catch (Exception ex)
            {
                OnException(ex);
            }

            return(dataSource);
        }
        public JsonResult AddRedirect(String source, String destination, Boolean isPermanent, Boolean rootMatching)
        {
            var result = new JsonResult();

            try
            {
                var redirect = new Redirect
                {
                    Source       = source,
                    Destination  = destination,
                    IsPermanent  = isPermanent,
                    RootMatching = rootMatching,
                    DateModified = DateTime.UtcNow,
                    IsActive     = true
                };
                Context.Redirects.Add(redirect);
                Context.SaveChanges();

                result.Data = new
                {
                    id      = redirect.RedirectId,
                    success = true
                };
                CachedObjects.GetRedirectsList(true);
                return(result);
            }
            catch
            {
                result.Data = new { success = false };
                return(result);
            }
        }
Пример #7
0
        public JsonResult ModifyModule(ContentModule entity)
        {
            var result = new JsonResult()
            {
                Data = new
                {
                    success = false,
                    message = "There as an error processing your request"
                }
            };

            if (String.IsNullOrEmpty(entity.ModuleName))
            {
                return(result);
            }

            var editedContent = Context.ContentModules.FirstOrDefault(x => x.ContentModuleId == entity.ContentModuleId);

            if (editedContent == null)
            {
                return(result);
            }

            if (editedContent.ParentContentModuleId.HasValue)
            {
                editedContent = Context.ContentModules.FirstOrDefault(x => x.ContentModuleId == editedContent.ParentContentModuleId.Value);
                if (editedContent == null)
                {
                    return(result);
                }
            }

            SaveDraft(editedContent, editedContent.CreateDate);

            editedContent.DraftAuthorName = UserUtils.CurrentMembershipUsername();
            editedContent.CreateDate      = DateTime.UtcNow;
            LoadContentFromUploadedModel(entity, editedContent);
            editedContent.IsActive = true;

            var success = Context.SaveChanges();

            if (success > 0)
            {
                CachedObjects.GetCacheContentModules(true);

                BookmarkUtil.UpdateTitle("/admin/modules/" + editedContent.ContentModuleId + "/", editedContent.ModuleName);
                result.Data = new
                {
                    success = true,
                    message = "Content saved successfully.",
                    date    = SystemTime.CurrentLocalTime.ToString("dd/MM/yyy @ h:mm tt")
                };
            }

            return(result);
        }
Пример #8
0
        protected TResult GetObject <TResult>(Func <TResult> createObject) where TResult : class
        {
            var key = typeof(TResult);

            if (!CachedObjects.ContainsKey(key))
            {
                CachedObjects.Add(key, createObject());
            }
            return(CachedObjects[key] as TResult);
        }
Пример #9
0
        public JsonResult SaveNavigationSet(int navigationId, string name, List <NavigationItem> items)
        {
            var result = new JsonResult()
            {
                Data = new
                {
                    success = false,
                    message = "There was an error processing your request."
                }
            };
            var success = 0;
            // Update the nav name
            var nav = Context.Navigations.FirstOrDefault(x => x.NavigationId == navigationId);

            nav.Name = name;

            // Make sure Nav Items aren't null
            items = items ?? new List <NavigationItem>();

            // Update the navigation children
            foreach (var navItem in items)
            {
                var item = Context.NavigationItems.FirstOrDefault(x => x.NavigationItemId == navItem.NavigationItemId);
                if (item != null)
                {
                    item.Name  = navItem.Name;
                    item.Href  = navItem.Href;
                    item.Order = navItem.Order;
                    item.ParentNavigationId     = navItem.ParentNavigationId;
                    item.ParentNavigationItemId = navItem.ParentNavigationItemId;
                    item.UsesContentPage        = navItem.UsesContentPage;
                    item.ContentPageId          = navItem.ContentPageId;
                    item.TargetBlank            = navItem.TargetBlank;
                    //item.Promo = navItem.Promo;
                }
            }

            success = Context.SaveChanges();

            if (success > 0)
            {
                // Clear the cache of the nav on save
                CachedObjects.GetCacheNavigationList(0, true);

                BookmarkUtil.DeleteBookmarkForUrl("/admin/navigation/editnav/" + navigationId + "/");

                result.Data = new
                {
                    success = true,
                    message = "Saved navigation successfully."
                };
            }

            return(result);
        }
        protected void ReturnInstance(GameObject objInstance, GameObject basePrefab)
        {
            Stack <GameObject> objStack;

            if (CachedObjects.TryGetValue(GetHash(basePrefab), out objStack))
            {
                objStack.Push(objInstance);
            }

            ReturnStuff(objInstance);
        }
Пример #11
0
        public JsonResult ModifyContent(ContentPageComplete page, bool isBasic)
        {
            var result = new JsonResult();

            if (page.Details == null || String.IsNullOrEmpty(page.Details.Title))
            {
                return(result);
            }

            if (String.IsNullOrEmpty(page.Details.Title))
            {
                return(result);
            }

            var editedContent =
                Context.ContentPages.FirstOrDefault(x => x.ContentPageId == page.Details.ContentPageId);

            if (editedContent == null)
            {
                return(result);
            }

            var contentUtility = new ContentUtils();

            if (contentUtility.CheckPermalink(page.Details.Permalink, page.Details.ContentPageId,
                                              page.Details.ParentNavigationItemId))
            {
                // permalink exists already under this parent page id
                result.Data = new
                {
                    permalinkExists = true
                };
                return(result);
            }

            SaveDraftInDb(page, editedContent.PublishDate);
            BookmarkUtil.UpdateTitle("/admin/pages/editcontent/" + editedContent.ContentPageId + "/", page.Details.Title);

            SetContentPageData(editedContent, page.Details, false, isBasic, null);
            UpdatePageExtenstion(page);
            editedContent.IsActive = true; // Saving / Publishing content sets this to true.
            editedContent.NoIndex  = page.Details.NoIndex;
            editedContent.NoFollow = page.Details.NoFollow;

            Context.SaveChanges();

            CachedObjects.GetCacheContentPages(true);

            result.Data = new { publishDate = SystemTime.CurrentLocalTime.ToString("MM/dd/yyyy @ hh:mm") };

            return(result);
        }
Пример #12
0
        public virtual async ValueTask <TEntity[]> GetAll()
        {
            if (CachedObjects == null || CachedObjects.Count == 0)
            {
                await DeferredUpdate();
            }
            else
            {
                DeferredUpdate().DontWait();
            }

            return(CachedObjects.ToArray());
        }
Пример #13
0
        public ActionResult NewContentModule(string schemaId, string editContentHeading)
        {
            // Create a new Content Module to be passed to the edit content action

            ContentModule module = GetDefaultContentModule();

            // If a schema was passed in, we will want to assign that schema id to the newly created module
            // We will also want to copy over html from an existing module that uses that html. That way the user has a consistent editor.
            int iSchemaId = !string.IsNullOrEmpty(schemaId) ? Int32.Parse(schemaId) : 0;

            if (iSchemaId > 0)
            {
                module.SchemaId = iSchemaId;

                var moduleToCloneFrom = Context.ContentModules.FirstOrDefault(x => x.SchemaId == iSchemaId);
                if (moduleToCloneFrom != null)
                {
                    module.HTMLContent  = moduleToCloneFrom.HTMLContent;
                    module.HTMLUnparsed = moduleToCloneFrom.HTMLUnparsed;
                    module.JSContent    = moduleToCloneFrom.JSContent;
                    module.CSSContent   = moduleToCloneFrom.CSSContent;
                }
            }

            Context.ContentModules.Add(module);
            Context.SaveChanges();

            // Update the module name
            var moduleId = module.ContentModuleId;

            module.ModuleName      = "Module " + moduleId;
            module.DraftAuthorName = UserUtils.CurrentMembershipUsername();

            Context.SaveChanges();

            CachedObjects.GetCacheContentModules(true);

            object routeParameters = new { id = moduleId };

            if (!String.IsNullOrEmpty(editContentHeading))
            {
                routeParameters = new { id = moduleId, editContentHeading };
            }

            return(RedirectToAction("EditModule", "Modules", routeParameters));
        }
Пример #14
0
        public JsonResult ModifyBlog(EditBlogModel entity)
        {
            if (String.IsNullOrEmpty(entity.Title))
            {
                return(NoBlogTitleError);
            }

            var blogEntity = Context.Blogs.FirstOrDefault(x => x.BlogId == entity.BlogId);

            if (blogEntity == null)
            {
                return(JsonErrorResult);
            }

            Mapper.Map(entity, blogEntity);
            // Database Nav property mappings
            blogEntity.Category   = Utils.GetCategoryOrUncategorized(entity.Category);
            blogEntity.BlogAuthor = Context.BlogUsers.First(usr => usr.UserId == entity.AuthorId);

            if (blogEntity.Tags == null)
            {
                blogEntity.Tags = new List <BlogTag>();
            }
            else
            {
                blogEntity.Tags.Clear();
            }

            if (!String.IsNullOrEmpty(entity.Tags))
            {
                foreach (var tag in entity.Tags.Split(','))
                {
                    blogEntity.Tags.Add(Utils.GetOrCreateTag(tag));
                }
            }

            var success = Context.SaveChanges();

            CachedObjects.GetCacheContentPages(true);
            BookmarkUtil.UpdateTitle("/admin/pages/editblog/" + blogEntity.BlogId + "/", entity.Title);

            return(success > 0
                ? BlogSaveSuccess(entity)
                : JsonErrorResult);
        }
Пример #15
0
        public JsonResult UpdateModuleShort(int id, string html)
        {
            var result = new JsonResult();


            var module = Context.ContentModules.FirstOrDefault(x => x.ContentModuleId == id);

            if (module != null)
            {
                module.HTMLContent = html;
            }

            Context.SaveChanges();

            CachedObjects.GetCacheContentModules(true);

            return(result);
        }
Пример #16
0
        private ContentViewViewModel GetSubDirectoryModel(string path)
        {
            var masterList = CachedObjects.GetCacheNavigationList(1);
            var pathPieces = path.Split('/');
            var permalink  = pathPieces.Last().ToLower();

            var currentPath       = "/" + pathPieces[0] + "/";
            var currentNavigation = masterList.FirstOrDefault(x => String.Equals(x.Href, currentPath, StringComparison.CurrentCultureIgnoreCase));

            foreach (var piece in pathPieces.Skip(1).Take(pathPieces.Count() - 2))
            {
                if (currentNavigation == null)
                {
                    break;
                }
                currentPath       = currentPath + piece + "/";
                currentNavigation =
                    currentNavigation.Children.FirstOrDefault(
                        x => String.Equals(x.Href, currentPath, StringComparison.CurrentCultureIgnoreCase));
            }

            if (currentNavigation == null)
            {
                return(null);
            }

            var thePage = CachedObjects.GetCacheContentPages().FirstOrDefault(x => x.Permalink == permalink && x.ParentNavigationItemId == currentNavigation.NavigationItemId);

            if (thePage == null)
            {
                thePage = Context.ContentPages.FirstOrDefault(x => x.Permalink == permalink && x.ParentNavigationItemId == currentNavigation.NavigationItemId);
            }

            if (thePage == null)
            {
                return(null);
            }

            var model = new ContentViewViewModel {
                ThePage = ContentLoader.GetDetailById(thePage.ContentPageId)
            };

            return(model);
        }
        public async Task <ObservableCollection <IFiltersItemVM> > LoadFiltersFor(string categoryId, List <ApplyedFilter> applyedFilters)
        {
            ObservableCollection <IFiltersItemVM> dataSource = null;

            try
            {
                IEnumerable <Filter> filters = null;

                if (categoryId.IsNullOrEmtpy())
                {
                    filters = await FiltersService.LoadFilters(categoryId);
                }
                else if (!CachedObjects.ContainsKey(categoryId))
                {
                    filters = await FiltersService.LoadFilters(categoryId);

                    if (!filters.IsNullOrEmpty())
                    {
                        CachedObjects.Add(categoryId, filters);
                    }
                }
                else if (CachedObjects.ContainsKey(categoryId))
                {
                    filters = CachedObjects[categoryId].Cast <Filter>();
                }

                dataSource = new ObservableCollection <IFiltersItemVM>(filters
                                                                       .Select(filter => CreateItemForFilter(filter, applyedFilters))
                                                                       .Where(x => x != null)
                                                                       );
            }
            catch (ConnectionException ex)
            {
                OnConnectionException(ex);
            }
            catch (Exception ex)
            {
                OnException(ex);
            }

            return(dataSource);
        }
Пример #18
0
        // May need to store host in distributed or multi-tenant applications
        protected void Application_BeginRequest()
        {
            // Find out if the redirect exists for this request path

            var allRedirects = CachedObjects.GetRedirectsList(false);

            if (allRedirects == null)
            {
                return;
            }

            Redirect redirect = allRedirects
                                .FirstOrDefault(
                x => (x.Source == Request.Path || x.Source + '/' == Request.Path || x.Source == Request.Path + '/') ||
                (x.RootMatching && Request.Path.StartsWith(x.Source) && !Request.Path.StartsWith(x.Destination)));

            // Check whether the browser remains connected to the server.
            if (Response.IsClientConnected)
            {
                if (redirect == null)
                {
                    return;
                }

                if (redirect.IsPermanent)
                {
                    Response.RedirectPermanent(redirect.Destination);
                }
                else
                {
                    // If still connected, redirect to another page.
                    Response.Redirect(redirect.Destination);
                }
            }
            else
            {
                // If the browser is not connected stop all response processing.
                Response.End();
            }
        }
Пример #19
0
        public async Task <ObservableCollection <ISortItemVM> > LoadSortTypesInCategory(string categoryId, string selectedSortId)
        {
            ObservableCollection <ISortItemVM> dataSource = null;

            try
            {
                IEnumerable <SortType> sortTypes = null;

                if (categoryId.IsNullOrEmtpy())
                {
                    sortTypes = await FiltersService.LoadSortTypes(categoryId);
                }
                else if (!CachedObjects.ContainsKey(categoryId))
                {
                    sortTypes = await FiltersService.LoadSortTypes(categoryId);

                    if (!sortTypes.IsNullOrEmpty())
                    {
                        CachedObjects.Add(categoryId, sortTypes);
                    }
                }
                else if (CachedObjects.ContainsKey(categoryId))
                {
                    sortTypes = CachedObjects[categoryId].Cast <SortType>();
                }

                dataSource = new ObservableCollection <ISortItemVM>(sortTypes.Select(c => SetupItem(c, selectedSortId)));
            }
            catch (ConnectionException ex)
            {
                OnConnectionException(ex);
            }
            catch (Exception ex)
            {
                OnException(ex);
            }

            return(dataSource);
        }
Пример #20
0
        public JsonResult ModifyContent(ContentPage entity, bool isBasic)
        {
            var result = new JsonResult();

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(result);
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(result);
            }

            ContentPage editedContent =
                Context.ContentPages.FirstOrDefault(x => x.ContentPageId == entity.ContentPageId);

            if (editedContent == null)
            {
                return(result);
            }

            SaveDraft(editedContent, editedContent.PublishDate);
            BookmarkUtil.UpdateTitle("/admin/pages/editcontent/" + editedContent.ContentPageId + "/", entity.Title);

            SetContentPageData(ref editedContent, entity, false, isBasic, null);
            editedContent.IsActive = true; // Saving / Publishing content sets this to true.
            editedContent.NoIndex  = entity.NoIndex;
            editedContent.NoFollow = entity.NoFollow;

            Context.SaveChanges();

            CachedObjects.GetCacheContentPages(true);

            result.Data = new { publishDate = Convert.ToDateTime(DateTime.UtcNow).ToString("MM/dd/yyyy @ hh:mm") };

            return(result);
        }
Пример #21
0
        public virtual async ValueTask <TEntity> Get(object id)
        {
            await GetAll();

            return(CachedObjects.FirstOrDefault(a => a.Id.Equals(id)));
        }
Пример #22
0
 public void ClearCache()
 {
     CachedObjects.ClearCache();
 }
 public HeaderPartialViewModel()
 {
     MainNav = CachedObjects.GetMasterNavigationList(false);
 }
Пример #24
0
        public JsonResult AddNewPageFromTemplate(string templatePath, string viewTemplate, string permalink, string title, int parent)
        {
            var result         = new JsonResult();
            var contentUtility = new ContentUtils();

            // check to see if permalink exists
            if (contentUtility.CheckPermalink(permalink, 0, parent))
            {
                result.Data = new
                {
                    success = false,
                    message = "Permalink is already in use."
                };
                return(result);
            }

            var urlLink = "";
            var page    = new ContentPage
            {
                Title                  = title,
                IsActive               = false,
                CreateDate             = DateTime.UtcNow,
                Permalink              = permalink,
                DisplayName            = permalink,
                ParentNavigationItemId = parent,
                Template               = !String.IsNullOrEmpty(viewTemplate) ? viewTemplate.ToLower() : "blank",
                HTMLUnparsed           = ContentUtils.RenderPartialViewToString(templatePath, null, ControllerContext, ViewData, TempData),
                HTMLContent            = ContentUtils.RenderPartialViewToString(templatePath, null, ControllerContext, ViewData, TempData)
            };

            try
            {
                Context.ContentPages.Add(page);
                Context.SaveChanges();

                page.HTMLContent = ContentUtils.ReplacePageParametersInHtmlContent(page.HTMLUnparsed, page);
                Context.SaveChanges();
            }
            catch (Exception)
            {
                result.Data = new
                {
                    success = false,
                    message = "Page could not be created."
                };
                return(result);
            }

            CachedObjects.GetCacheContentPages(true);

            var parentHref = NavigationUtils.GetNavItemUrl(parent);

            if (!String.IsNullOrEmpty(parentHref))
            {
                urlLink = parentHref + page.Permalink;
            }

            urlLink     = string.IsNullOrEmpty(urlLink) ? "/" + page.Permalink : urlLink;
            result.Data = new
            {
                id      = page.ContentPageId,
                url     = urlLink,
                success = true,
                message = "Page created, redirecting."
            };

            return(result);
        }
Пример #25
0
        public JsonResult ModifyBlog(EditBlogModel entity)
        {
            if (String.IsNullOrEmpty(entity.Title))
            {
                return(new JsonResult
                {
                    Data = new
                    {
                        success = false,
                        message = "Your post must have a title"
                    }
                });
            }

            var editedBlog = Context.Blogs.FirstOrDefault(x => x.BlogId == entity.BlogId);

            if (editedBlog == null)
            {
                return(JsonErrorResult);
            }

            // Straight copies from the model
            editedBlog.AuthorId    = entity.AuthorId;
            editedBlog.HtmlContent = entity.HtmlContent;
            editedBlog.IsActive    = entity.IsActive;
            editedBlog.IsFeatured  = entity.IsFeatured;
            editedBlog.ShortDesc   = entity.ShortDesc;
            editedBlog.Date        = entity.Date;
            // Meta
            editedBlog.Canonical       = entity.Canonical;
            editedBlog.OGImage         = entity.OGImage;
            editedBlog.OGTitle         = entity.OGTitle;
            editedBlog.OGType          = entity.OGType;
            editedBlog.OGUrl           = entity.OGUrl;
            editedBlog.MetaDescription = entity.MetaDescription;

            // Cleaned inpuit
            editedBlog.Title     = ContentUtils.ScrubInput(entity.Title);
            editedBlog.ImageUrl  = ContentUtils.ScrubInput(entity.ImageUrl);
            editedBlog.PermaLink = ContentUtils.GetFormattedUrl(entity.PermaLink);

            // Database Nav property mappings
            editedBlog.Category   = utils.GetCategoryOrUncategorized(entity.Category);
            editedBlog.BlogAuthor = Context.BlogUsers.First(usr => usr.UserId == entity.AuthorId);

            if (editedBlog.Tags == null)
            {
                editedBlog.Tags = new List <BlogTag>();
            }

            if (!String.IsNullOrEmpty(entity.Tags))
            {
                foreach (var tag in entity.Tags.Split(','))
                {
                    editedBlog.Tags.Add(utils.GetOrCreateTag(tag));
                }
            }

            var success = Context.SaveChanges();

            CachedObjects.GetCacheContentPages(true);
            BookmarkUtil.UpdateTitle("/admin/pages/editblog/" + editedBlog.BlogId + "/", entity.Title);

            if (success > 0)
            {
                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        message = "Blog saved successfully.",
                        id = entity.BlogId
                    }
                });
            }

            return(JsonErrorResult);
        }