Beispiel #1
0
        protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new PublishLaterViewModel(part);

            updater.TryUpdateModel(model, Prefix, null, null);

            if (Services.WorkContext.Resolve <IHttpContextAccessor>().Current().Request.Form["submit.Save"] == "submit.PublishLater")
            {
                if (!string.IsNullOrWhiteSpace(model.ScheduledPublishDate) && !string.IsNullOrWhiteSpace(model.ScheduledPublishTime))
                {
                    DateTime scheduled;
                    string   parseDateTime = String.Concat(model.ScheduledPublishDate, " ", model.ScheduledPublishTime);

                    // use an english culture as it is the one used by jQuery.datepicker by default
                    if (DateTime.TryParse(parseDateTime, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.AssumeLocal, out scheduled))
                    {
                        model.ScheduledPublishUtc = part.ScheduledPublishUtc.Value = scheduled.ToUniversalTime();
                        _publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.Value);
                    }
                    else
                    {
                        updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime));
                    }
                }
                else if (!string.IsNullOrWhiteSpace(model.ScheduledPublishDate) || !string.IsNullOrWhiteSpace(model.ScheduledPublishTime))
                {
                    updater.AddModelError(Prefix, T("Both the date and time need to be specified for when this is to be published. If you don't want to schedule publishing then click Save or Publish Now."));
                }
            }

            return(ContentShape("Parts_PublishLater_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)));
        }
Beispiel #2
0
        protected override DriverResult Editor(PublishLaterPart part, dynamic shapeHelper)
        {
            // date and time are formatted using the same patterns as DateTimePicker is, preventing other cultures issues
            var model = new PublishLaterViewModel(part)
            {
                ScheduledPublishUtc  = part.ScheduledPublishUtc.Value,
                ScheduledPublishDate = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? part.ScheduledPublishUtc.Value.Value.ToLocalTime().ToString(DatePattern, CultureInfo.InvariantCulture) : String.Empty,
                ScheduledPublishTime = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? part.ScheduledPublishUtc.Value.Value.ToLocalTime().ToString(TimePattern, CultureInfo.InvariantCulture) : String.Empty
            };

            return(ContentShape("Parts_PublishLater_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)));
        }
        protected override DriverResult Editor(PublishLaterPart part, dynamic shapeHelper)
        {
            // date and time are formatted using the same patterns as DateTimePicker is, preventing other cultures issues
            var localDate = new Lazy <DateTime>(() => TimeZoneInfo.ConvertTimeFromUtc(part.ScheduledPublishUtc.Value.Value, Services.WorkContext.CurrentTimeZone));
            var model     = new PublishLaterViewModel(part)
            {
                ScheduledPublishUtc  = part.ScheduledPublishUtc.Value,
                ScheduledPublishDate = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? localDate.Value.ToString("d", _cultureInfo.Value) : String.Empty,
                ScheduledPublishTime = part.ScheduledPublishUtc.Value.HasValue && !part.IsPublished() ? localDate.Value.ToString("t", _cultureInfo.Value) : String.Empty,
            };

            return(ContentShape("Parts_PublishLater_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)));
        }
Beispiel #4
0
        protected override DriverResult Editor(PublishLaterPart part, dynamic shapeHelper)
        {
            var model = new PublishLaterViewModel(part)
            {
                Editor = new DateTimeEditor()
                {
                    ShowDate = true,
                    ShowTime = true,
                    Date     = !part.IsPublished() ? _dateServices.ConvertToLocalDateString(part.ScheduledPublishUtc.Value, "") : "",
                    Time     = !part.IsPublished() ? _dateServices.ConvertToLocalTimeString(part.ScheduledPublishUtc.Value, "") : "",
                }
            };

            return(ContentShape("Parts_PublishLater_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)));
        }
        protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new PublishLaterViewModel(part);

            updater.TryUpdateModel(model, Prefix, null, null);
            var httpContext = _httpContextAccessor.Current();

            if (httpContext.Request.Form["submit.Save"] == "submit.PublishLater")
            {
                if (!string.IsNullOrWhiteSpace(model.ScheduledPublishDate) && !string.IsNullOrWhiteSpace(model.ScheduledPublishTime))
                {
                    DateTime scheduled;

                    string parseDateTime = String.Concat(model.ScheduledPublishDate, " ", model.ScheduledPublishTime);

                    // use current culture
                    if (DateTime.TryParse(parseDateTime, _cultureInfo.Value, DateTimeStyles.None, out scheduled))
                    {
                        // the date time is entered locally for the configured timezone
                        var timeZone = Services.WorkContext.CurrentTimeZone;

                        model.ScheduledPublishUtc = part.ScheduledPublishUtc.Value = TimeZoneInfo.ConvertTimeToUtc(scheduled, timeZone);

                        if (model.ScheduledPublishUtc < _clock.UtcNow)
                        {
                            updater.AddModelError("ScheduledPublishUtcDate", T("You cannot schedule a publishing date in the past"));
                        }
                        else
                        {
                            _publishLaterService.Publish(model.ContentItem, model.ScheduledPublishUtc.Value);
                        }
                    }
                    else
                    {
                        updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime));
                    }
                }
                else if (!string.IsNullOrWhiteSpace(model.ScheduledPublishDate) || !string.IsNullOrWhiteSpace(model.ScheduledPublishTime))
                {
                    updater.AddModelError(Prefix, T("Both the date and time need to be specified for when this is to be published. If you don't want to schedule publishing then click Save or Publish Now."));
                }
            }

            return(ContentShape("Parts_PublishLater_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)));
        }
Beispiel #6
0
        protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new PublishLaterViewModel(part);

            updater.TryUpdateModel(model, Prefix, null, null);
            var httpContext = _httpContextAccessor.Current();

            if (httpContext.Request.Form["submit.Save"] == "submit.PublishLater")
            {
                if (!String.IsNullOrWhiteSpace(model.Editor.Date) && !String.IsNullOrWhiteSpace(model.Editor.Time))
                {
                    try {
                        var utcDateTime = _dateServices.ConvertFromLocalString(model.Editor.Date, model.Editor.Time);
                        if (utcDateTime.HasValue)
                        {
                            if (utcDateTime.Value < _clock.UtcNow)
                            {
                                updater.AddModelError("ScheduledPublishUtcDate", T("You cannot schedule a publishing date in the past."));
                            }
                            else
                            {
                                _publishLaterService.Publish(model.ContentItem, utcDateTime.Value);
                            }
                        }
                    }
                    catch (FormatException) {
                        updater.AddModelError(Prefix, T("'{0} {1}' could not be parsed as a valid date and time.", model.Editor.Date, model.Editor.Time));
                    }
                }
                else if (!String.IsNullOrWhiteSpace(model.Editor.Date) || !String.IsNullOrWhiteSpace(model.Editor.Time))
                {
                    updater.AddModelError(Prefix, T("Both the date and time need to be specified for when this is to be published. If you don't want to schedule publishing then click Save or Publish Now."));
                }
            }

            return(ContentShape("Parts_PublishLater_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix)));
        }