protected override DriverResult Editor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) { var model = BuildViewModelFromPart(part); if (updater.TryUpdateModel(model, Prefix, null, null)) { if (model.ArchiveLater) { try { var utcDateTime = _dateLocalizationServices.ConvertFromLocalizedString(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(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) { var model = new ArchiveLaterViewModel(part); if (updater.TryUpdateModel(model, Prefix, null, null)) { if (model.ArchiveLater) { DateTime scheduled; var parseDateTime = String.Concat(model.ScheduledArchiveDate, " ", model.ScheduledArchiveTime); // use an english culture as it is the one used by jQuery.datepicker by default 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.ScheduledArchiveUtc = TimeZoneInfo.ConvertTimeToUtc(scheduled, timeZone); _archiveLaterService.ArchiveLater(model.ContentItem, model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value : DateTime.MaxValue); } else { updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime)); } } else { _archiveLaterService.RemoveArchiveLaterTasks(model.ContentItem); } } return(ContentShape("Parts_ArchiveLater_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix))); }