protected override DriverResult Editor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) { var model = new ArchiveLaterViewModel(part); if (updater.TryUpdateModel(model, Prefix, null, null)) { if (model.ArchiveLater) { try { var utcDateTime = _dateServices.ConvertFromLocalString(model.Editor.Date, model.Editor.Time); _archiveLaterService.ArchiveLater(model.ContentItem, utcDateTime.HasValue ? utcDateTime.Value : DateTime.MaxValue); } 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 { _archiveLaterService.RemoveArchiveLaterTasks(model.ContentItem); } } return(ContentShape("Parts_ArchiveLater_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.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))); }
protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) { var settings = part.TypePartDefinition.Settings.GetModel <DateEditorSettings>(); if (!settings.ShowDateEditor) { return(null); } return(ContentShape( "Parts_Common_Date_Edit", () => { DateEditorViewModel model = shapeHelper.Parts_Common_Date_Edit(typeof(DateEditorViewModel)); model.Editor = new DateTimeEditor() { ShowDate = true, ShowTime = true }; if (part.CreatedUtc != null) { // show CreatedUtc only if is has been "touched", // i.e. it has been published once, or CreatedUtc has been set var itemHasNeverBeenPublished = part.PublishedUtc == null; var thisIsTheInitialVersionRecord = part.ContentItem.Version < 2; var theDatesHaveNotBeenModified = part.CreatedUtc == part.VersionCreatedUtc; var theEditorShouldBeBlank = itemHasNeverBeenPublished && thisIsTheInitialVersionRecord && theDatesHaveNotBeenModified; if (!theEditorShouldBeBlank) { model.Editor.Date = _dateServices.ConvertToLocalDateString(part.CreatedUtc, ""); model.Editor.Time = _dateServices.ConvertToLocalTimeString(part.CreatedUtc, ""); } } if (updater != null) { updater.TryUpdateModel(model, Prefix, null, null); if (!String.IsNullOrWhiteSpace(model.Editor.Date) && !String.IsNullOrWhiteSpace(model.Editor.Time)) { try { var utcDateTime = _dateServices.ConvertFromLocalString(model.Editor.Date, model.Editor.Time); part.CreatedUtc = utcDateTime; part.VersionCreatedUtc = utcDateTime; } 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.")); } // Neither date/time part is specified => do nothing. } return model; })); }