Пример #1
0
        public IActionResult EditPost(PostViewModel post)
        {
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            try
            {
                Entry entry = _mapper.Map <Entry>(post);

                entry.Author    = "admin";              //TODO: Need to integrate with context security
                entry.Language  = "en-us";              //TODO: We inject this fron http context?
                entry.Latitude  = null;
                entry.Longitude = null;

                EntrySaveState sts = _blogManager.UpdateEntry(entry);
                if (sts != EntrySaveState.Updated)
                {
                    ModelState.AddModelError("", "Failed to edit blog post");
                    return(View(post));
                }
            }
            catch (Exception e)
            {
                RedirectToAction("Error");
            }

            return(View(post));
        }
        public string UpdateEntry(Entry entry, string username, string password)
        {
            SiteConfig siteConfig = SiteConfig.GetSiteConfig();

            if (!siteConfig.EnableEditService)
            {
                throw new ServiceDisabledException();
            }

            Authenticate(username, password);

            ILoggingDataService logService  = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
            IBlogDataService    dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);

            EntrySaveState val = SiteUtilities.UpdateEntry(entry, null, null, siteConfig, logService, dataService);

            string rtn = string.Empty;

            if (val.Equals(EntrySaveState.Updated))
            {
                rtn = entry.EntryId;
            }
            else
            {
                rtn = val.ToString();
            }

            return(rtn);
        }
Пример #3
0
        public IActionResult CreatePost(PostViewModel post)
        {
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            try
            {
                Entry entry = _mapper.Map <Entry>(post);

                entry.Initialize();
                entry.Author    = _httpContextAccessor.HttpContext.User.Identity.Name;
                entry.Language  = "en-us";                //TODO: We inject this fron http context?
                entry.Latitude  = null;
                entry.Longitude = null;

                EntrySaveState sts = _blogManager.CreateEntry(entry);
                if (sts != EntrySaveState.Added)
                {
                    ModelState.AddModelError("", "Failed to create blog post");
                    return(View(post));
                }
            }
            catch (Exception e)
            {
                RedirectToAction("Error");
            }

            return(View("Views/BlogPost/EditPost.cshtml", post));
        }
Пример #4
0
        private EntrySaveState InternalSaveEntry(Entry entry, TrackbackInfoCollection trackbackList, CrosspostInfoCollection crosspostList)
        {
            EntrySaveState rtn = EntrySaveState.Failed;

            // we want to prepopulate the cross post collection with the crosspost footer
            if (dasBlogSettings.SiteConfiguration.EnableCrossPostFooter && dasBlogSettings.SiteConfiguration.CrossPostFooter != null &&
                dasBlogSettings.SiteConfiguration.CrossPostFooter.Length > 0)
            {
                foreach (CrosspostInfo info in crosspostList)
                {
                    info.CrossPostFooter = dasBlogSettings.SiteConfiguration.CrossPostFooter;
                }
            }

            // now save the entry, passign in all the necessary Trackback and Pingback info.
            try
            {
                // if the post is missing a title don't publish it
                if (entry.Title == null || entry.Title.Length == 0)
                {
                    entry.IsPublic = false;
                }

                // if the post is missing categories, then set the categories to empty string.
                if (entry.Categories == null)
                {
                    entry.Categories = "";
                }

                rtn = dataService.SaveEntry(
                    entry,
                    MaybeBuildWeblogPingInfo(),
                    entry.IsPublic
                                                ? trackbackList
                                                : null,
                    MaybeBuildPingbackInfo(entry),
                    crosspostList);

                //TODO: SendEmail(entry, siteConfig, logService);
            }
            catch (Exception ex)
            {
                //TODO: Do something with this????
                // StackTrace st = new StackTrace();
                // logService.AddEvent(new EventDataItem(EventCodes.Error, ex.ToString() + Environment.NewLine + st.ToString(), ""));

                LoggedException le  = new LoggedException("file failure", ex);
                var             edi = new EventDataItem(EventCodes.Error, null
                                                        , "Failed to Save a Post on {date}", System.DateTime.Now.ToShortDateString());
                logger.LogError(edi, le);
            }

            // we want to invalidate all the caches so users get the new post
            // BreakCache(entry.GetSplitCategories());

            return(rtn);
        }
Пример #5
0
        private EntrySaveState InternalSaveEntry(Entry entry, TrackbackInfoCollection trackbackList, CrosspostInfoCollection crosspostList)
        {
            EntrySaveState rtn = EntrySaveState.Failed;

            // we want to prepopulate the cross post collection with the crosspost footer
            if (_dasBlogSettings.SiteConfiguration.EnableCrossPostFooter && _dasBlogSettings.SiteConfiguration.CrossPostFooter != null &&
                _dasBlogSettings.SiteConfiguration.CrossPostFooter.Length > 0)
            {
                foreach (CrosspostInfo info in crosspostList)
                {
                    info.CrossPostFooter = _dasBlogSettings.SiteConfiguration.CrossPostFooter;
                }
            }

            // now save the entry, passign in all the necessary Trackback and Pingback info.
            try
            {
                // if the post is missing a title don't publish it
                if (entry.Title == null || entry.Title.Length == 0)
                {
                    entry.IsPublic = false;
                }

                // if the post is missing categories, then set the categories to empty string.
                if (entry.Categories == null)
                {
                    entry.Categories = "";
                }

                rtn = _dataService.SaveEntry(entry,
                                             (_dasBlogSettings.SiteConfiguration.PingServices.Count > 0) ?
                                             new WeblogUpdatePingInfo(_dasBlogSettings.SiteConfiguration.Title, _dasBlogSettings.GetBaseUrl(), _dasBlogSettings.GetBaseUrl(), _dasBlogSettings.RsdUrl, _dasBlogSettings.SiteConfiguration.PingServices) : null,
                                             (entry.IsPublic) ?
                                             trackbackList : null,
                                             _dasBlogSettings.SiteConfiguration.EnableAutoPingback && entry.IsPublic ?
                                             new PingbackInfo(
                                                 _dasBlogSettings.GetPermaLinkUrl(entry.EntryId),
                                                 entry.Title,
                                                 entry.Description,
                                                 _dasBlogSettings.SiteConfiguration.Title) : null,
                                             crosspostList);

                //TODO: SendEmail(entry, siteConfig, logService);
            }
            catch (Exception ex)
            {
                //TODO: Do something with this????
                // StackTrace st = new StackTrace();
                // logService.AddEvent(new EventDataItem(EventCodes.Error, ex.ToString() + Environment.NewLine + st.ToString(), ""));
            }

            // we want to invalidate all the caches so users get the new post
            // TODO: BreakCache(entry.GetSplitCategories());

            return(rtn);
        }
Пример #6
0
        public IActionResult CreatePost(PostViewModel post, string submit)
        {
            post.Languages = GetAlllanguages();
            if (submit == Constants.BlogPostAddCategoryAction)
            {
                return(HandleNewCategory(post));
            }

            if (submit == Constants.UploadImageAction)
            {
                return(HandleImageUpload(post));
            }

            ValidatePost(post);
            if (!ModelState.IsValid)
            {
                return(View(post));
            }
            if (!string.IsNullOrWhiteSpace(post.NewCategory))
            {
                ModelState.AddModelError(nameof(post.NewCategory)
                                         , $"Please click 'Add' to add the category, \"{post.NewCategory}\" or clear the text before continuing");
                return(View(post));
            }

            try
            {
                Entry entry = mapper.Map <Entry>(post);

                entry.Initialize();
                entry.Author    = httpContextAccessor.HttpContext.User.Identity.Name;
                entry.Language  = post.Language;
                entry.Latitude  = null;
                entry.Longitude = null;

                EntrySaveState sts = blogManager.CreateEntry(entry);
                if (sts != EntrySaveState.Added)
                {
                    ModelState.AddModelError("", "Failed to create blog post. Please check Logs for more details.");
                    return(View(post));
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message, null);
                ModelState.AddModelError("", "Failed to edit blog post. Please check Logs for more details.");
            }

            return(View("views/blogpost/editPost.cshtml", post));
        }
Пример #7
0
        public IActionResult EditPost(PostViewModel post, string submit)
        {
            // languages does not get posted as part of form
            post.Languages = GetAlllanguages();
            if (submit == Constants.BlogPostAddCategoryAction)
            {
                return(HandleNewCategory(post));
            }
            if (submit == Constants.UploadImageAction)
            {
                return(HandleImageUpload(post));
            }
            if (!ModelState.IsValid)
            {
                return(View(post));
            }

            if (!string.IsNullOrWhiteSpace(post.NewCategory))
            {
                ModelState.AddModelError(nameof(post.NewCategory)
                                         , $"Please click 'Add' to add the category, \"{post.NewCategory}\" or clear the text before continuing");
                return(View(post));
            }
            try
            {
                Entry entry = _mapper.Map <Entry>(post);

                entry.Author    = _httpContextAccessor.HttpContext.User.Identity.Name;
                entry.Language  = "en-us";                //TODO: We inject this fron http context?
                entry.Latitude  = null;
                entry.Longitude = null;

                EntrySaveState sts = _blogManager.UpdateEntry(entry);
                if (sts != EntrySaveState.Updated)
                {
                    ModelState.AddModelError("", "Failed to edit blog post");
                    return(View(post));
                }
            }
            catch (Exception e)
            {
                RedirectToAction("Error");
            }

            return(View(post));
        }
Пример #8
0
        public static void FixIsPublic(string path)
        {
            ContentPath = path;

            BlogDataServiceFactory.RemoveService(path);
            IBlogDataService dataService = BlogDataServiceFactory.GetService(ContentPath, null);
            EntryCollection  entries     = dataService.GetEntriesForDay(
                DateTime.MaxValue.AddDays(-2),
                TimeZone.CurrentTimeZone,
                String.Empty,
                int.MaxValue,
                int.MaxValue,
                String.Empty);

            foreach (Entry e in entries)
            {
                //if (e.IsPublic == false)
                {
                    try
                    {
                        Entry edit = dataService.GetEntryForEdit(e.EntryId);
                        edit.IsPublic = true;

                        if (edit.Categories == String.Empty)
                        {
                            edit.Categories = "Main";
                        }
                        EntrySaveState saved = dataService.SaveEntry(edit);

                        if (saved == EntrySaveState.Failed)
                        {
                            WriteLine(String.Format("Failed saving {0}", e.Title));
                        }
                        else
                        {
                            WriteLine(String.Format("Saved {0}", e.Title));
                        }
                    }
                    catch (Exception e1)
                    {
                        WriteLine(String.Format("Failed saving {0}, {1}", e.Title, e1.ToString()));
                    }
                }
            }
        }