Ejemplo n.º 1
0
        public User(Guid?id, string email, string username, string password, string salt, string birthDate,
                    string fullName, string firstName, string middleName, string lastName, string encryptionScheme,
                    DateTimeOffset?expiry, bool active, string timezone, Guid?cleanSpeakId,
                    Dictionary <string, object> data, bool verified,
                    ContentStatus usernameStatus, TwoFactorDelivery twoFactorDelivery, bool twoFactorEnabled,
                    string twoFactorSecret, Uri imageUrl, params UserRegistration[] registrations)
        {
            this.id                = id;
            this.email             = email;
            this.password          = password;
            this.salt              = salt;
            this.birthDate         = birthDate;
            this.encryptionScheme  = encryptionScheme;
            this.expiry            = expiry;
            this.active            = active;
            this.username          = username;
            this.timezone          = timezone;
            this.fullName          = fullName;
            this.firstName         = firstName;
            this.middleName        = middleName;
            this.lastName          = lastName;
            this.cleanSpeakId      = cleanSpeakId;
            this.verified          = verified;
            this.usernameStatus    = usernameStatus;
            this.twoFactorDelivery = twoFactorDelivery;
            this.twoFactorEnabled  = twoFactorEnabled;
            this.twoFactorSecret   = twoFactorSecret;
            this.imageUrl          = imageUrl;

            for (var i = 0; i < registrations.Length; i++)
            {
                this.registrations.Add(registrations[i]);
            }
        }
Ejemplo n.º 2
0
        public static IQueryable <T> FilterByUser <T>(this IQueryable <T> query, ContentStatus status, IIdentity user) where T : ContentBase
        {
            bool isAllowedGetAll = UserPermissions.IsAllowedToGetAll(user, status);

            return(query.FilterIf(!isAllowedGetAll, x =>
                                  ((status == ContentStatus.All) && (x.Status == ContentStatus.Published)) || (x.UserId == user.GetUserIdentity())));
        }
Ejemplo n.º 3
0
        public async Task SetCategoryStatus(Guid categoryId, ContentStatus status)
        {
            var category = await CategoryAccessor.OneAsync <Categories>(x => x.Id == categoryId);

            category.Status = status;
            await CategoryAccessor.Update(category);
        }
Ejemplo n.º 4
0
        public async Task SetStatusAsync(int id, ContentStatus status)
        {
            Content content = _db.Content.Where(p => p.Id == id).FirstOrDefault();

            content.Status = status;
            await UpdateAsync(content);
        }
Ejemplo n.º 5
0
        public IActionResult GetIdsForExhibit(int exhibitId, ContentStatus status = ContentStatus.Published)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (status == ContentStatus.Deleted && !UserPermissions.IsAllowedToGetDeleted(User.Identity))
            {
                return(Forbid());
            }

            var exhibit = _db.Database.GetCollection <Exhibit>(ResourceType.Exhibit.Name)
                          .AsQueryable()
                          .FirstOrDefault(x => x.Id == exhibitId);

            if (exhibit == null)
            {
                return(NotFound());
            }

            var pageIds = exhibit.Pages
                          .LoadAll(_db.Database)
                          .AsQueryable()
                          .Where(p => status == ContentStatus.All || p.Status == status)
                          .FilterIf(status == ContentStatus.All, x => x.Status != ContentStatus.Deleted)
                          .Select(p => p.Id)
                          .ToList();

            return(Ok(pageIds));
        }
Ejemplo n.º 6
0
        public void CreateCategory(string name, ContentStatus status, params string[] tags)
        {
            var hasCategory = dbContext.Set <Categories>().Any(x => x.Name == name);

            if (!hasCategory)
            {
                var tagsList = new List <Tags>();
                if (tags != null || tags.Length > 1)
                {
                    foreach (var tag in tags)
                    {
                        tagsList.Add(new Tags
                        {
                            Id   = Guid.NewGuid(),
                            Name = tag
                        });
                    }
                }
                var cateCartoon = GetTopCategory("漫画");
                var category    = new Categories
                {
                    Id             = Guid.NewGuid(),
                    CreateTime     = DateTime.Now,
                    Name           = name,
                    Tags           = tagsList,
                    ParentCategory = cateCartoon,
                    Status         = status
                };
                dbContext.Set <Categories>().Add(category);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        private void LogChange(Component component, ContentStatus status)
        {
            ContentVersionInfo info = new ContentVersionInfo
            {
                ComponentID = component.ID,
                ParentID    = component.ParentID,
                Status      = status,
                Component   = component,
                Date        = DateTime.Now
            };

            switch (_type)
            {
            case ApplicationType.Diction:
                if (ChangesDiction.FindIndex(x => x.ComponentID == component.ID && x.ParentID == component.ParentID) == -1)
                {
                    ChangesDiction.Add(info);
                }
                else
                {
                    info           = ChangesDiction.Find(x => x.ComponentID == component.ID && x.ParentID == component.ParentID);
                    info.ParentID  = component.ParentID;
                    info.Status    = status;
                    info.Component = component;
                }
                break;

            case ApplicationType.Teachers:
                if (ChangesTeachers.FindIndex(x => x.ComponentID == component.ID && x.ParentID == component.ParentID) == -1)
                {
                    ChangesTeachers.Add(info);
                }
                else
                {
                    info           = ChangesTeachers.Find(x => x.ComponentID == component.ID && x.ParentID == component.ParentID);
                    info.ParentID  = component.ParentID;
                    info.Status    = status;
                    info.Component = component;
                }
                break;

            case ApplicationType.Audio:
                if (ChangesAudio.FindIndex(x => x.ComponentID == component.ID && x.ParentID == component.ParentID) == -1)
                {
                    ChangesAudio.Add(info);
                }
                else
                {
                    info           = ChangesAudio.Find(x => x.ComponentID == component.ID && x.ParentID == component.ParentID);
                    info.ParentID  = component.ParentID;
                    info.Status    = status;
                    info.Component = component;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
 private void EditContentStatus_Shown(object sender, EventArgs e)
 {
     if (this._editableId != -1)
     {
         this._entity     = ApplicationMap.ContentStatus[this._editableId];
         this.nameTB.Text = _entity.Name;
     }
 }
Ejemplo n.º 9
0
 public static bool IsAllowedToGetAll(IIdentity identity, ContentStatus status)
 {
     if (status == ContentStatus.Published)
     {
         return(true);
     }
     return(CheckRoles(identity));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Gets the name of the status.
 /// </summary>
 /// <param name="status">The status.</param>
 /// <returns>The name of the status</returns>
 public string GetStatusName(ContentStatus status)
 {
     if (statusNames.ContainsKey(status))
     {
         return(statusNames[status]);
     }
     return(null);
 }
        public void Add(Guid id, ContentStatus status)
        {
            if (_holder.ContainsKey(id))
                throw new InvalidOperationException("Connection is already exists.");

            if (!_holder.TryAdd(id, status))
                throw new InvalidOperationException("Fail to add.");
        }
        public void Change(Guid id, ContentStatus status)
        {
            ContentStatus prevStatus;
            if (!_holder.TryGetValue(id, out prevStatus))
                throw new InvalidOperationException("Connection wasn't found.");

            if (!_holder.TryUpdate(id, status, prevStatus))
                throw new InvalidOperationException("Fail to update.");
        }
Ejemplo n.º 13
0
 public IPosts GetPosts(uint page = 1, uint limit = 15, ContentStatus status = ContentStatus.All, bool withStaticPages = false)
 {
     return(Cmd("/posts/")
            .WithParameter("page", page)
            .WithParameter("limit", limit)
            .WithParameter("status", ContentStatusHelper.ToGhostString(status))
            .WithParameter("staticPages", withStaticPages.ToString().ToLower())
            .Execute().To <Posts>(JsonHelper.CheckResponseForError));
 }
Ejemplo n.º 14
0
        public async Task SetStatusAsync(int id, ContentStatus status)
        {
            PropertyListing property = _db.Properties.Where(p => p.Id == id).FirstOrDefault();

            property.Status = status;
            await _db.SaveChangesAsync();

            ClearPropertyCache(property.Id);
        }
Ejemplo n.º 15
0
 public IPosts GetPosts(uint page = 1, uint limit = 15, ContentStatus status = ContentStatus.All, bool withStaticPages = false)
 {
     return Cmd("/posts/")
         .WithParameter("page", page)
         .WithParameter("limit", limit)
         .WithParameter("status", ContentStatusHelper.ToGhostString(status))
         .WithParameter("staticPages", withStaticPages.ToString().ToLower())
         .Execute().To<Posts>(JsonHelper.CheckResponseForError);
 }
Ejemplo n.º 16
0
 public FollowMylistViewModel(MylistId id, NvapiMylistItem followMylist, ContentStatus status)
 {
     _followMylist = followMylist;
     Status        = status;
     PlaylistId    = new PlaylistId()
     {
         Id = id, Origin = PlaylistItemsSourceOrigin.Mylist
     };
 }
Ejemplo n.º 17
0
        public static bool IsAllowedToDelete(IIdentity identity, ContentStatus status, string ownerId)
        {
            bool isOwner = ownerId == identity.GetUserIdentity();

            if (status != ContentStatus.Published && isOwner)
            {
                return(true);
            }

            return(CheckRoles(identity));
        }
Ejemplo n.º 18
0
 public TagResult(Tag tag)
 {
     Id          = tag.Id;
     Title       = tag.Title;
     Description = tag.Description;
     UserId      = tag.UserId;
     Image       = tag.Image.Id.AsNullableInt32;
     Used        = tag.Referencers.Count > 0;
     Status      = tag.Status;
     Timestamp   = tag.Timestamp;
 }
Ejemplo n.º 19
0
 internal bool Begin(Perspective Perspective)
 {
     //_logger.Debug("コンテントを開始状態に遷移します(Content = {})", _Name);
     if (Status != ContentStatus.Idle && Status != ContentStatus.Suspend)
     {
         throw new ApplicationException(string.Format("状態が不正です(Status={0})", Status));
     }
     _Perspective      = Perspective;
     TransitionRollbak = ContentStatus.Idle;
     Status            = ContentStatus.PreResume;
     return(OnPreResume()); // Resume状態へ遷移してよいか?
 }
Ejemplo n.º 20
0
 public async Task DeleteAllVersions(string contentType, string contentId, ContentStatus versionStatus)
 {
     _connectDb.ContentVersions.RemoveRange
     (
         _connectDb.ContentVersions.Where
             (x =>
             x.ContentType == contentType &&
             x.ContentId == contentId &&
             x.Status == versionStatus
             )
     );
     await _connectDb.SaveChangesAsync();
 }
Ejemplo n.º 21
0
        public virtual async Task <Response> SetStatus(int id, ContentStatus status)
        {
            try
            {
                await _property.SetStatusAsync(id, status);

                return(new Response(true, "Property status has been updated successfully."));
            }
            catch (Exception ex)
            {
                return(await ErrorResponseAsync <BasePropertyController>($"Error publishing/archiving property with Id: {id}", ex));
            }
        }
Ejemplo n.º 22
0
        internal bool Suspend()
        {
            //_logger.Debug("コンテントをサスペンド状態に遷移します(Content = {})", _Name);
            if (Status != ContentStatus.Run)
            {
                throw new ApplicationException("状態が不正です");
            }
            bProgressStop    = false;
            bProgressSuspend = true;

            TransitionRollbak = ContentStatus.Run;
            Status            = ContentStatus.PreStop;
            return(OnPreStop()); // Stop状態へ遷移してよいか?
        }
Ejemplo n.º 23
0
        public static bool IsAllowedToCreate(IIdentity identity, ContentStatus status)
        {
            if (status == ContentStatus.Deleted)
            {
                return(false);
            }

            if (status != ContentStatus.Published && CheckRoles(identity, UserRoles.Student))
            {
                return(true);
            }

            return(CheckRoles(identity));
        }
Ejemplo n.º 24
0
        public IActionResult GetIds(ContentStatus status = ContentStatus.Published)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (status == ContentStatus.Deleted && !UserPermissions.IsAllowedToGetDeleted(User.Identity))
            {
                return(Forbid());
            }

            return(Ok(_entityIndex.AllIds(ResourceType.Media, status, User.Identity)));
        }
Ejemplo n.º 25
0
        public virtual async Task <Response> SetStatus(int id, ContentStatus status)
        {
            try
            {
                await _content.SetStatusAsync(id, status);

                Content content = await _content.GetContentByIdAsync(id);

                return(new Response(true, "Content status has been updated successfully."));
            }
            catch (Exception ex)
            {
                return(await ErrorResponseAsync <BaseContentController>($"Error publishing content with Id: {id}", ex));
            }
        }
Ejemplo n.º 26
0
 private void Dispose(bool v)
 {
     if (v)
     {
         this.ContentInterpreter = null;
         _status             = ContentStatus.Disposing;
         this.Info           = null;
         this.ContentChanged = null;
         this.Source         = null;
         this.StateChanged   = null;
         this.Stream         = null;
         this.VolumeCurve    = null;
         this._status        = ContentStatus.Disposed;
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Checks whether a certain user is allowed to get entities of a certain status and owner.
        /// </summary>
        /// <param name="identity">User identity</param>
        /// <param name="status">Current status of the queried entity</param>
        /// <param name="ownerId">Owner of the queried entity</param>
        public static bool IsAllowedToGet(IIdentity identity, ContentStatus status, string ownerId)
        {
            if (status == ContentStatus.Deleted)
            {
                return(CheckRoles(identity, AllowedToGetDeletedContent));
            }

            bool isOwner = ownerId == identity.GetUserIdentity();

            if (status == ContentStatus.Published || isOwner)
            {
                return(true);
            }

            return(CheckRoles(identity));
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Gets the IDs of all entities of the given type and status.
 /// </summary>
 public IReadOnlyCollection <int> AllIds(ResourceType entityType, ContentStatus status, IIdentity user)
 {
     lock (_lockObject)
     {
         bool   isAllowedGetAll = UserPermissions.IsAllowedToGetAll(user, status);
         string userId          = user.GetUserIdentity();
         var    info            = GetOrCreateEntityTypeInfo(entityType);
         return(info.Entities
                .AsQueryable()
                .FilterIf(!isAllowedGetAll, x =>
                          ((status == ContentStatus.All) && (x.Value.Status == ContentStatus.Published)) || (x.Value.UserId == userId))
                .FilterIf(status == ContentStatus.All, x => x.Value.Status != ContentStatus.Deleted)
                .Where(x => status == ContentStatus.All || x.Value.Status == status)
                .Select(x => x.Key)
                .ToList());
     }
 }
Ejemplo n.º 29
0
        public async Task <IActionResult> GetRouteActivityAsync(ContentStatus status = ContentStatus.Published)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userId = User.Identity.GetUserIdentity();
            var token  = Request.Headers["Authorization"];

            var routes = await GetContentIdsAsync(status, token, ResourceTypes.Route);

            routes = await RemoveIdsAsync(routes, ResourceTypes.Route,
                                          userId, token);

            return(Ok(routes));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Saves the child content options..
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="viewModels">The list of view models with provided child content id and option values list.</param>
        /// <param name="requestedStatus">The requested status for saving content.</param>
        public void SaveChildContentOptions(Models.Content content, IList <ContentOptionValuesViewModel> viewModels,
                                            ContentStatus requestedStatus)
        {
            if (viewModels == null)
            {
                viewModels = new ContentOptionValuesViewModel[0];
            }

            Models.Content contentToUdpate = null;
            if ((requestedStatus == ContentStatus.Draft || requestedStatus == ContentStatus.Preview) &&
                content != null &&
                requestedStatus != content.Status &&
                content.History != null)
            {
                contentToUdpate = content.History.FirstOrDefault(c => c.Status == requestedStatus);
            }
            if (contentToUdpate == null)
            {
                contentToUdpate = content;
            }

            if (contentToUdpate != null && contentToUdpate.ChildContents != null)
            {
                foreach (var childContent in contentToUdpate.ChildContents)
                {
                    var viewModel = viewModels.FirstOrDefault(vm => vm.OptionValuesContainerId == childContent.AssignmentIdentifier);
                    if (viewModel == null)
                    {
                        continue;
                    }

                    IList <OptionValueEditViewModel> optionValues        = viewModel.OptionValues;
                    IList <ChildContentOption>       childContentOptions = null;

                    if (childContent.Options != null)
                    {
                        childContentOptions = childContent.Options.Distinct().ToList();
                    }

                    SaveOptionValues(optionValues, childContentOptions, () => new ChildContentOption {
                        ChildContent = childContent
                    });
                }
            }
        }
 public UserRegistration(Guid?id, Guid applicationId, Guid userId, DateTimeOffset?lastLoginInstant,
                         string username,
                         ContentStatus usernameStatus, Guid?cleanSpeakId, Dictionary <string, object> data,
                         params string[] roles)
 {
     this.id               = id;
     this.applicationId    = applicationId;
     this.userId           = userId;
     this.cleanSpeakId     = cleanSpeakId;
     this.data             = data;
     this.lastLoginInstant = lastLoginInstant;
     this.username         = username;
     this.usernameStatus   = usernameStatus;
     for (var i = 0; i < roles.Length; i++)
     {
         this.roles.Add(roles[i]);
     }
 }
Ejemplo n.º 32
0
        public static int GetApprovedConentStatusId(DKBSDbContext dbContext)
        {
            var contentStatus = dbContext.ContentStatus.FirstOrDefault(p => p.Description.ToLower() == "approved");

            if (contentStatus == null)
            {
                contentStatus = new ContentStatus
                {
                    Description    = "Approved",
                    CreatedBy      = "Migration",
                    CreatedDate    = DateTime.Now,
                    LastModifiedBy = "Migration",
                    LastModified   = DateTime.Now
                };
                dbContext.ContentStatus.Add(contentStatus);
                dbContext.SaveChanges();
            }
            return(contentStatus.ContentStatusId);
        }
        public void Update()
        {
            if (!IsValid)
            {
                return;
            }

            if (null != m_ContentRoot && InspectionContext.ApplyInspectorStyling)
            {
                StylingUtility.AlignInspectorLabelWidth(m_ContentRoot);
            }

            var state = Provider.MoveNext();

            if (m_PreviousState != state)
            {
                m_ContentRoot?.ClearTarget();
                switch (state)
                {
                case ContentStatus.ContentUnavailable:
                    return;

                case ContentStatus.ContentNotReady:
                    SetNotReadyContent();
                    break;

                case ContentStatus.ContentReady:
                    SetTarget();
                    break;

                case ContentStatus.ReloadContent:
                    SetNotReadyContent();
                    Load();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            m_PreviousState = state;
        }
Ejemplo n.º 34
0
        public Models.Content SaveContentWithStatusUpdate(Models.Content updatedContent, ContentStatus requestedStatus)
        {
            if (updatedContent == null)
            {
                throw new CmsException("Nothing to save.", new ArgumentNullException("updatedContent"));
            }

            if (requestedStatus == ContentStatus.Archived)
            {
                throw new CmsException(string.Format("Can't switch a content to the Archived state directly."));
            }

            // Fill content with dynamic contents info
            var dynamicContainer = updatedContent as IDynamicContentContainer;
            if (dynamicContainer != null)
            {
                if (updatedContent.ContentRegions == null)
                {
                    updatedContent.ContentRegions = new List<ContentRegion>();
                }
                CollectDynamicRegions(dynamicContainer.Html, updatedContent, updatedContent.ContentRegions);
            }

            if (updatedContent.Id == default(Guid))
            {
                /* Just create a new content with requested status.*/
                if (requestedStatus == ContentStatus.Published)
                {
                    if (!updatedContent.PublishedOn.HasValue)
                    {
                        updatedContent.PublishedOn = DateTime.Now;
                    }
                    if (string.IsNullOrWhiteSpace(updatedContent.PublishedByUser))
                    {
                        updatedContent.PublishedByUser = securityService.CurrentPrincipalName;
                    }
                }

                updatedContent.Status = requestedStatus;
                repository.Save(updatedContent);

                return updatedContent;
            }
            
            var originalContent =
                repository.AsQueryable<Models.Content>()
                          .Where(f => f.Id == updatedContent.Id && !f.IsDeleted)
                          .Fetch(f => f.Original).ThenFetchMany(f => f.History)
                          .Fetch(f => f.Original).ThenFetchMany(f => f.ContentOptions)
                          .FetchMany(f => f.History)
                          .FetchMany(f => f.ContentOptions)            
                          .FetchMany(f => f.ContentRegions)            
                          .ThenFetch(f => f.Region)
                          .ToList()
                          .FirstOrDefault();

            if (originalContent == null)
            {
                throw new EntityNotFoundException(typeof(Models.Content), updatedContent.Id);
            }
            
            if (originalContent.Original != null)
            {
                originalContent = originalContent.Original;
            }

            originalContent = repository.UnProxy(originalContent);

            if (originalContent.History != null)
            {
                originalContent.History = originalContent.History.Distinct().ToList();
            }
            else
            {
                originalContent.History = new List<Models.Content>();
            }

            if (originalContent.ContentOptions != null)
            {
                originalContent.ContentOptions = originalContent.ContentOptions.Distinct().ToList();
            }

            if (originalContent.ContentRegions != null)
            {
                originalContent.ContentRegions = originalContent.ContentRegions.Distinct().ToList();
            }
            
            /* Update existing content. */
            switch (originalContent.Status)
            {
                case ContentStatus.Published:
                    SavePublishedContentWithStatusUpdate(originalContent, updatedContent, requestedStatus);
                    break;

                case ContentStatus.Preview:
                case ContentStatus.Draft:
                    SavePreviewOrDraftContentWithStatusUpdate(originalContent, updatedContent, requestedStatus);
                    break;

                case ContentStatus.Archived:
                    throw new CmsException(string.Format("Can't edit a content in the {0} state.", originalContent.Status));

                default:
                    throw new CmsException(string.Format("Unknown content status {0}.", updatedContent.Status), new NotSupportedException());
            }

            return originalContent;
        }
Ejemplo n.º 35
0
        private void SavePreviewOrDraftContentWithStatusUpdate(Models.Content originalContent, Models.Content updatedContent, ContentStatus requestedStatus)
        {
            /* 
             * Edit preview or draft content:
             * -> Save as preview or draft - look for preview or draft version in a history list or create a new history version with requested preview status with reference to an original content.
             * -> Save draft - just update field and save.
             * -> Publish - look if the published content (look for original) exists:
             *              - published content exits:
             *                  | create a history content version of the published (clone it). update original with draft data and remove draft|preview.
             *              - published content not exists:
             *                  | save draft content as published
             */            
            if (requestedStatus == ContentStatus.Preview || requestedStatus == ContentStatus.Draft)
            {
                var previewOrDraftContentVersion = originalContent.History.FirstOrDefault(f => f.Status == requestedStatus && !f.IsDeleted);
                if (previewOrDraftContentVersion == null)
                {
                    if (originalContent.Status == requestedStatus 
                        || (originalContent.Status == ContentStatus.Preview && requestedStatus == ContentStatus.Draft))
                    {
                        previewOrDraftContentVersion = originalContent;
                    }
                    else
                    {
                        previewOrDraftContentVersion = originalContent.Clone();
                        previewOrDraftContentVersion.Original = originalContent;
                        originalContent.History.Add(previewOrDraftContentVersion);
                    }
                }

                updatedContent.CopyDataTo(previewOrDraftContentVersion, false, false);
                SetContentOptions(previewOrDraftContentVersion, updatedContent);
                SetContentRegions(previewOrDraftContentVersion, updatedContent);
                previewOrDraftContentVersion.Status = requestedStatus;
                repository.Save(previewOrDraftContentVersion); 
            }            
            else if (requestedStatus == ContentStatus.Published)
            {
                var publishedVersion = originalContent.History.FirstOrDefault(f => f.Status == requestedStatus && !f.IsDeleted);
                if (publishedVersion != null)
                {
                    var originalToArchive = originalContent.Clone();
                    originalToArchive.Status = ContentStatus.Archived;
                    originalToArchive.Original = originalContent;
                    originalContent.History.Add(originalToArchive);
                    repository.Save(originalToArchive);
                }

                updatedContent.CopyDataTo(originalContent, false, false);
                SetContentOptions(originalContent, updatedContent);
                SetContentRegions(originalContent, updatedContent);
                originalContent.Status = requestedStatus;
                if (!originalContent.PublishedOn.HasValue)
                {
                    originalContent.PublishedOn = DateTime.Now;
                }
                if (string.IsNullOrWhiteSpace(originalContent.PublishedByUser))
                {
                    originalContent.PublishedByUser = securityService.CurrentPrincipalName;
                }

                repository.Save(originalContent);
            }
        }
Ejemplo n.º 36
0
        private void SavePublishedContentWithStatusUpdate(Models.Content originalContent, Models.Content updatedContent, ContentStatus requestedStatus)
        {            
            /* 
             * Edit published content:
             * -> Save as draft, preview - look for draft|preview version in history list or create a new history version with requested status (draft, preview) with reference to an original content.
             * -> Publish - current published version should be cloned to archive version with reference to original (archive state) and original updated with new data (published state).
             *              Look for preview|draft versions - if exists remote it.
             */
            if (requestedStatus == ContentStatus.Preview || requestedStatus == ContentStatus.Draft)
            {
                var contentVersionOfRequestedStatus = originalContent.History.FirstOrDefault(f => f.Status == requestedStatus && !f.IsDeleted);
                if (contentVersionOfRequestedStatus == null)
                {
                    contentVersionOfRequestedStatus = originalContent.Clone();
                }

                updatedContent.CopyDataTo(contentVersionOfRequestedStatus, false, false);
                SetContentOptions(contentVersionOfRequestedStatus, updatedContent);
                SetContentRegions(contentVersionOfRequestedStatus, updatedContent);

                contentVersionOfRequestedStatus.Original = originalContent;
                contentVersionOfRequestedStatus.Status = requestedStatus;
                originalContent.History.Add(contentVersionOfRequestedStatus);
                repository.Save(contentVersionOfRequestedStatus);                
            }
            
            if (requestedStatus == ContentStatus.Published)
            {
                // Original is copied with options and saved.
                // Removes options from original.
                // Locks new stuff from view model.

                var originalToArchive = originalContent.Clone();
                originalToArchive.Status = ContentStatus.Archived;
                originalToArchive.Original = originalContent;
                originalContent.History.Add(originalToArchive);
                repository.Save(originalToArchive);

                updatedContent.CopyDataTo(originalContent, false, false);
                SetContentOptions(originalContent, updatedContent);
                SetContentRegions(originalContent, updatedContent);

                originalContent.Status = requestedStatus;
                if (!originalContent.PublishedOn.HasValue)
                {
                    originalContent.PublishedOn = DateTime.Now;
                }
                if (string.IsNullOrWhiteSpace(originalContent.PublishedByUser))
                {
                    originalContent.PublishedByUser = securityService.CurrentPrincipalName;
                }
                repository.Save(originalContent);

                IList<Models.Content> contentsToRemove = originalContent.History.Where(f => f.Status == ContentStatus.Preview || f.Status == ContentStatus.Draft).ToList();
                foreach (var redundantContent in contentsToRemove)
                {
                    repository.Delete(redundantContent);
                    originalContent.History.Remove(redundantContent);
                }
            }
        }
Ejemplo n.º 37
0
 /// <summary>
 /// Gets the name of the status.
 /// </summary>
 /// <param name="status">The status.</param>
 /// <returns>The name of the status</returns>
 public string GetStatusName(ContentStatus status)
 {
     if (statusNames.ContainsKey(status))
     {
         return statusNames[status];
     }
     return null;
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="status">New status</param>
 public ContentStatusChangedEventArgs(ContentStatus status)
 {
     NewStatus = status;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Updates the status.
 /// </summary>
 /// <param name="blogPost">The blog post.</param>
 /// <param name="desirableStatus">The desirable status.</param>
 /// <exception cref="CmsException">If <c>desirableStatus</c> is not supported.</exception>
 private void UpdateStatus(BlogPost blogPost, ContentStatus desirableStatus)
 {
     switch (desirableStatus)
     {
         case ContentStatus.Published:
             blogPost.Status = PageStatus.Published;
             blogPost.PublishedOn = DateTime.Now;
             break;
         case ContentStatus.Draft:
             blogPost.Status = PageStatus.Unpublished;
             break;
         case ContentStatus.Preview:
             blogPost.Status = PageStatus.Preview;
             break;
         default:
             throw new CmsException(string.Format("Blog post does not support status: {0}.", desirableStatus));
     }
 }
Ejemplo n.º 40
0
 public static string ToGhostString(ContentStatus status)
 {
     return status.ToString().ToLower();
 }