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))); }
/// POST api/<controller> ///{ /// "Advertising": { /// "Title": "Comunicato Sms - Id 5007", /// "SmsGateway": { /// "Id": 5007, /// "Text": "Test invio da WSKrakeAdvertisingSms", /// "PhoneNumbers": [ /// "393401831897" /// ] /// }, /// "DatePublish": "2016-12-23T13:00:00Z" /// } ///} public AdvertisingCommunicationAPIResult Post(AdvertisingCommunication adv) { int communicationAdvertising_Id = -1; string errorString = ""; string infoAdvertising = ""; try { if (adv == null) { errorString = T("The provided data does not correspond to the required format.").ToString(); } else { // Create Advertising ContentItem content = _contentManager.New("CommunicationAdvertising"); // Check permissions User if (_orchardServices.Authorizer.Authorize(Permissions.PublishCommunicationAdv, content, T("Couldn't create content"))) { ((dynamic)content).TitlePart.Title = adv.Advertising.Title; _communicationEventHandlers.PopulateChannel(content, adv.Advertising); _contentManager.Create(content, VersionOptions.Draft); // Data Publish in formato UTC DateTime dataPublish = adv.Advertising.DatePublish; if (dataPublish == null || dataPublish == DateTime.MinValue) { dataPublish = DateTime.UtcNow; } if (dataPublish.CompareTo(DateTime.UtcNow) > 0) { // Publish Later _publishLaterService.Publish(content, dataPublish); } else { // Publish _contentManager.Publish(content); } communicationAdvertising_Id = content.Id; infoAdvertising = T("Create Advertising Id: {0} - Title: {1}", content.Id, adv.Advertising.Title).ToString(); } else { infoAdvertising = T("User couldn't create Advertising").ToString(); } } } catch (Exception ex) { errorString = ex.Message; Logger.Error(T("Creating CommunicationAdvertising failed: {0}", ex.Message).Text); } return(new AdvertisingCommunicationAPIResult { Id = communicationAdvertising_Id, Error = errorString, Information = infoAdvertising }); }
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))); }
protected override DriverResult Editor(PublishLaterPart part, IUpdateModel updater, dynamic shapeHelper) { var model = BuildViewModelFromPart(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 = _dateLocalizationServices.ConvertFromLocalizedString(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 { 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 Draft or Publish.")); } } if (httpContext.Request.Form["submit.Save"] == "submit.CancelPublishLaterTasks") { _publishingTaskManager.DeleteTasks(model.ContentItem); } return(ContentShape("Parts_PublishLater_Edit", () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix))); }