public override async Task <IDisplayResult> UpdateAsync(DateTimeField field, IUpdateModel updater, UpdateFieldEditorContext context)
        {
            var model = new EditDateTimeFieldViewModel();

            if (await updater.TryUpdateModelAsync(model, Prefix, f => f.LocalDateTime))
            {
                var settings = context.PartFieldDefinition.GetSettings <DateTimeFieldSettings>();
                if (settings.Required && model.LocalDateTime == null)
                {
                    updater.ModelState.AddModelError(Prefix, nameof(model.LocalDateTime), S["A value is required for {0}.", context.PartFieldDefinition.DisplayName()]);
                }
                else
                {
                    if (model.LocalDateTime == null)
                    {
                        field.Value = null;
                    }
                    else
                    {
                        field.Value = await _localClock.ConvertToUtcAsync(model.LocalDateTime.Value);
                    }
                }
            }

            return(Edit(field, context));
        }
예제 #2
0
 /// <summary>
 /// Converts the given local date to UTC using the given time-zone by temporarily setting it in the HTTP
 /// context.
 /// </summary>
 /// <param name="dateTimeLocal">Local date.</param>
 /// <param name="timeZoneId">IANA time-zone ID.</param>
 /// <param name="localClock">IANA time-zone ID.</param>
 /// <param name="httpContext">HTTP context to be used to temporarily set in the HTTP context.</param>
 /// <returns>UTC date.</returns>
 public static async Task <DateTime> ConvertToUtcAsync(
     this ILocalClock localClock,
     DateTime dateTimeLocal,
     string timeZoneId,
     HttpContext httpContext) =>
 await ExecuteInDifferentTimeZone(
     httpContext,
     timeZoneId,
     async() => await localClock.ConvertToUtcAsync(dateTimeLocal));
        public override async Task <IDisplayResult> UpdateAsync(DateTimeField field, IUpdateModel updater, UpdateFieldEditorContext context)
        {
            var model = new EditDateTimeFieldViewModel();

            if (await updater.TryUpdateModelAsync(model, Prefix, f => f.LocalDateTime))
            {
                if (model.LocalDateTime == null)
                {
                    field.Value = null;
                }
                else
                {
                    field.Value = await _localClock.ConvertToUtcAsync(model.LocalDateTime.Value);
                }
            }

            return(Edit(field, context));
        }
        public override async Task <IDisplayResult> UpdateAsync(UnpublishLaterPart part, IUpdateModel updater, UpdatePartEditorContext context)
        {
            var httpContext = _httpContextAccessor.HttpContext;

            if (await _authorizationService.AuthorizeAsync(httpContext?.User, CommonPermissions.PublishContent, part.ContentItem))
            {
                var viewModel = new UnpublishLaterPartViewModel();

                await updater.TryUpdateModelAsync(viewModel, Prefix);

                if (viewModel.ScheduledUnpublishLocalDateTime == null || httpContext !.Request.Form["submit.Save"] == "submit.CancelUnpublishLater")
                {
                    part.ScheduledUnpublishUtc = null;
                }
                else
                {
                    part.ScheduledUnpublishUtc = await _localClock.ConvertToUtcAsync(viewModel.ScheduledUnpublishLocalDateTime.Value);
                }
            }
        public override async Task <IDisplayResult> UpdateAsync(CommonPart part, IUpdateModel updater)
        {
            var settings = GetSettings(part);

            if (settings.DisplayDateEditor)
            {
                var model = new DateEditorViewModel();
                await updater.TryUpdateModelAsync(model, Prefix);

                if (model.LocalDateTime == null)
                {
                    part.ContentItem.CreatedUtc = null;
                }
                else
                {
                    part.ContentItem.CreatedUtc = await _localClock.ConvertToUtcAsync(model.LocalDateTime.Value);
                }
            }

            return(Edit(part));
        }