Exemplo n.º 1
0
        private void AddContentProperty(ContentTranslationVersion currentVersion, IContentTypeProperty property, CultureInfo culture)
        {
            ContentTranslationVersionProperty currentVersionProperty;

            if (currentVersion.TryGetProperty(property.Name, out currentVersionProperty))
            {
                _internalProperties.Add(new ContentProperty(currentVersionProperty.SerializedValue, culture, this, property));
            }
            else
            {
                _internalProperties.Add(new ContentProperty(this, property, culture));
            }
        }
Exemplo n.º 2
0
        public ContentTranslationVersion GetVersion(CultureInfo culture, DateTime?dateTime = null, bool published = false)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            dateTime = dateTime ?? DependencyResolver.Current.GetService <IDateTimeManager>().Now();
            ContentTranslationVersion contentTranslationVersion = null;

            if (published)
            {
                //if (!HasPublishedVersion)
                //    throw new InvalidOperationException("The content has not been published yet.");

                var publicatedVersions = PreviousVersions.Where(v => v.Publication != null).ToList();
                if (publicatedVersions.Any())
                {
                    var latestPublication = publicatedVersions.OrderByDescending(v => v.CreationDate)
                                            .Select(v => v.Publication).First();

                    if (dateTime <= latestPublication.EndingDate)
                    {
                        contentTranslationVersion = PreviousVersions.OrderByDescending(p => p.CreationDate).FirstOrDefault(v =>
                                                                                                                           v.Culture.Equals(culture) && v.Publication != null &&
                                                                                                                           v.Publication.StartingDate <= dateTime && v.Publication.EndingDate >= dateTime);
                    }
                }
            }
            else
            {
                //Ici le CreationDate représente la fin de vie d'une version draft
                contentTranslationVersion = GetVersions().OrderBy(v => v.CreationDate).FirstOrDefault(v =>
                                                                                                      v.Culture.Equals(culture) && v.Publication == null && v.CreationDate > dateTime.Value);
            }

            return(contentTranslationVersion);
        }