Exemple #1
0
 private DateTimeEditor GetDateTimeEditor(DateTime?dateTime)
 {
     return(new DateTimeEditor {
         ShowDate = true,
         ShowTime = true,
         Date = _dateLocalizationServices.ConvertToLocalizedDateString(dateTime),
         Time = _dateLocalizationServices.ConvertToLocalizedTimeString(dateTime)
     });
 }
        public ActionResult Create()
        {
            var now = _clock.UtcNow;
            var localizationOptions = new DateLocalizationOptions {
                EnableTimeZoneConversion = true
            };
            var viewModel = new CustomSitemapEntryEditViewModel
            {
                LastModifiedUtc = new DateTimeEditor
                {
                    Date     = _dateLocalizationServices.ConvertToLocalizedDateString(now, localizationOptions),
                    Time     = _dateLocalizationServices.ConvertToLocalizedTimeString(now, localizationOptions),
                    ShowDate = true,
                    ShowTime = true
                }
            };

            return(View(viewModel));
        }
        protected override DriverResult Editor(PaymentPart part, dynamic shapeHelper)
        {
            var model = new PaymentEditViewModel()
            {
                AmountPaid    = part.AmountPaid,
                PayableAmount = part.PayableAmount,
                Transactions  = part.Transactions.Select(t => new PaymentTransactionEditViewModel()
                {
                    Id   = t.Id,
                    Date = new DateTimeEditor()
                    {
                        ShowDate = true,
                        ShowTime = true,
                        Date     = _dateServices.ConvertToLocalizedDateString(t.Date),
                        Time     = _dateServices.ConvertToLocalizedTimeString(t.Date),
                    },
                    Method        = t.Method,
                    TransactionId = t.TransactionId,
                    Status        = t.Status,
                    Amount        = t.Amount
                }).ToArray(),
                NewTransaction = new PaymentTransactionEditViewModel()
                {
                    Date = new DateTimeEditor()
                    {
                        ShowDate = true,
                        ShowTime = true,
                        Date     = _dateServices.ConvertToLocalizedDateString(_clock.UtcNow),
                        Time     = _dateServices.ConvertToLocalizedTimeString(_clock.UtcNow),
                    },
                    Status = TransactionStatus.Validated,
                    Amount = part.PayableAmount - part.AmountPaid
                }
            };

            return(ContentShape("Parts_Payment_Edit",
                                () => shapeHelper.EditorTemplate(
                                    TemplateName: TemplateName,
                                    Model: model,
                                    Prefix: Prefix)
                                ));
        }
 private PublishLaterViewModel BuildViewModelFromPart(PublishLaterPart part)
 {
     return(new PublishLaterViewModel(part)
     {
         Editor = new DateTimeEditor()
         {
             ShowDate = true,
             ShowTime = true,
             Date = !part.IsPublished() ? _dateLocalizationServices.ConvertToLocalizedDateString(part.ScheduledPublishUtc.Value) : "",
             Time = !part.IsPublished() ? _dateLocalizationServices.ConvertToLocalizedTimeString(part.ScheduledPublishUtc.Value) : "",
         }
     });
 }
Exemple #5
0
 private ArchiveLaterViewModel BuildViewModelFromPart(ArchiveLaterPart part)
 {
     return(new ArchiveLaterViewModel(part)
     {
         ArchiveLater = part.ScheduledArchiveUtc.Value.HasValue,
         Editor = new DateTimeEditor()
         {
             ShowDate = true,
             ShowTime = true,
             Date = _dateLocalizationServices.ConvertToLocalizedDateString(part.ScheduledArchiveUtc.Value),
             Time = _dateLocalizationServices.ConvertToLocalizedTimeString(part.ScheduledArchiveUtc.Value),
         }
     });
 }
Exemple #6
0
        private DateTimeEditor InitialDateTimeEditor(DateTime?value, DateTimeFieldDisplays displays = DateTimeFieldDisplays.DateAndTime)
        {
            var showDate = displays == DateTimeFieldDisplays.DateAndTime || displays == DateTimeFieldDisplays.DateOnly;
            var showTime = displays == DateTimeFieldDisplays.DateAndTime || displays == DateTimeFieldDisplays.TimeOnly;
            var editor   = new DateTimeEditor()
            {
                ShowDate                   = showDate,
                ShowTime                   = showTime,
                Date                       = value != null?_dateLocalizationServices.ConvertToLocalizedDateString(value) : null,
                                      Time = value != null?_dateLocalizationServices.ConvertToLocalizedTimeString(value) : null
            };

            return(editor);
        }
Exemple #7
0
 public override IEnumerable <TemplateViewModel> PartFieldEditor(ContentPartFieldDefinition definition)
 {
     if (definition.FieldDefinition.Name == "DateTimeField")
     {
         var model = definition.Settings.GetModel <DateTimeFieldSettings>();
         model.Editor = new DateTimeEditor()
         {
             ShowDate = true,
             ShowTime = true,
             Date     = _dateLocalizationServices.ConvertToLocalizedDateString(model.DefaultValue),
             Time     = _dateLocalizationServices.ConvertToLocalizedTimeString(model.DefaultValue),
         };
         yield return(DefinitionTemplate(model));
     }
 }
Exemple #8
0
        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;

                    // Dates are assumed the same if the millisecond part is the only difference.
                    // This is because SqlCe doesn't support high precision times (Datetime2) and the infoset does
                    // implying some discrepancies between values read from different storage mechanism.
                    var theDatesHaveNotBeenModified = DateUtils.DatesAreEquivalent(part.CreatedUtc, part.VersionCreatedUtc);

                    var theEditorShouldBeBlank =
                        itemHasNeverBeenPublished &&
                        thisIsTheInitialVersionRecord &&
                        theDatesHaveNotBeenModified;

                    if (!theEditorShouldBeBlank)
                    {
                        model.Editor.Date = _dateLocalizationServices.ConvertToLocalizedDateString(part.CreatedUtc);
                        model.Editor.Time = _dateLocalizationServices.ConvertToLocalizedTimeString(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 = _dateLocalizationServices.ConvertFromLocalizedString(model.Editor.Date, model.Editor.Time);
                            part.CreatedUtc = 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;
            }));
        }