private async Task <ContentTask> GetNotifications(string id, ContentTask customTask, bool isContentQuery) { var notifications = await GetNotifications(PrincipalInfo.CurrentPrincipal.Identity.Name, id, isContentQuery); if (notifications != null && notifications.PagedResult != null && notifications.PagedResult.Any()) { //Mark Notification Read foreach (var notification in notifications.PagedResult) { await _userNotificationRepository.MarkUserNotificationAsReadAsync(new NotificationUser(PrincipalInfo.CurrentPrincipal.Identity.Name), notification.ID); } customTask.NotificationUnread = true; } else { customTask.NotificationUnread = false; } return(customTask); }
private async Task <List <ContentTask> > ProcessChangeData(int pageNumber, int pageSize, string sorting, AdvancedTaskIndexViewData model) { //List of All task for the user var query = new ApprovalQuery { Status = ApprovalStatus.InReview, Username = PrincipalInfo.CurrentPrincipal.Identity.Name, Reference = new Uri("changeapproval:") }; var list = await _approvalRepository.ListAsync(query, (pageNumber - 1) *pageSize, pageSize); model.TotalItemsCount = Convert.ToInt32(list.TotalCount); var taskList = new List <ContentTask>(); foreach (var task in list.PagedResult) { IContent content = null; var id = task.ID.ToString(); var customTask = new ContentTask { ApprovalId = task.ID, DateTime = task.ActiveStepStarted.ToString("dd MMMM HH:mm"), StartedBy = task.StartedBy, URL = PageEditing.GetEditUrl(new ContentReference(task.ID)).Replace(".contentdata:", ".changeapproval:") }; if (!(task is ContentApproval)) { var taskDetails = _changeTaskHelper.GetData(task.ID); if (taskDetails != null) { customTask.Type = taskDetails.Type; customTask.ContentName = taskDetails.Name; customTask.Details = taskDetails.Details; } if (task.Reference != null) { if (!string.IsNullOrEmpty(task.Reference.AbsolutePath)) { var pageId = task.Reference.AbsolutePath.Replace("/", ""); int.TryParse(pageId, out var contentId); if (contentId != 0) { _contentRepository.TryGet(new ContentReference(contentId), out content); } } } if (content != null) { customTask.ContentReference = content.ContentLink; customTask.ContentType = GetTypeContent(content); } customTask = await GetNotifications(id, customTask, false); taskList.Add(customTask); } } taskList = SortColumns(sorting, taskList); return(taskList); }
private async Task <List <ContentTask> > ProcessContentData(int pageNumber, int pageSize, string sorting, AdvancedTaskIndexViewData model, string taskValues, string approvalComment) { if (!string.IsNullOrEmpty(taskValues)) { await ApproveContent(taskValues, approvalComment); } //List of All task for the user var query = new ApprovalQuery { Status = ApprovalStatus.InReview, Username = PrincipalInfo.CurrentPrincipal.Identity.Name, Reference = new Uri("content:") }; var list = await _approvalRepository.ListAsync(query, (pageNumber - 1) *pageSize, pageSize); model.TotalItemsCount = Convert.ToInt32(list.TotalCount); var taskList = new List <ContentTask>(); foreach (var task in list.PagedResult) { var id = task.ID.ToString(); var customTask = new ContentTask { ApprovalId = task.ID, DateTime = task.ActiveStepStarted.ToString("dd MMMM HH:mm"), StartedBy = task.StartedBy }; if (task is ContentApproval approval) { _contentRepository.TryGet(approval.ContentLink, out IContent content); if (content != null) { customTask.URL = PageEditing.GetEditUrl(approval.ContentLink); id = content.ContentLink.ID.ToString(); var canUserPublish = await _helper.CanUserPublish(content); customTask.CanUserPublish = canUserPublish; customTask.ContentReference = content.ContentLink; customTask.ContentName = content.Name; customTask.ContentType = GetTypeContent(content); if (content is PageData) { customTask.Type = "Page"; } else if (content is BlockData) { customTask.Type = "Block"; if (!string.IsNullOrWhiteSpace(customTask.ContentType) && customTask.ContentType.Equals("Form container")) { customTask.Type = "Form"; } } else if (content is ImageData) { customTask.Type = "Image"; } else if (content is MediaData) { customTask.Type = "Media"; if (!string.IsNullOrWhiteSpace(customTask.ContentType) && customTask.ContentType.Equals("Video")) { customTask.Type = "Video"; } } var enableContentApprovalDeadline = bool.Parse(ConfigurationManager.AppSettings["ATM:EnableContentApprovalDeadline"] ?? "false"); var warningDays = int.Parse(ConfigurationManager.AppSettings["ATM:WarningDays"] ?? "4"); if (enableContentApprovalDeadline) { //Deadline Property of The Content var propertyData = content.Property.Get(ContentApprovalDeadlinePropertyName) ?? content.Property[ContentApprovalDeadlinePropertyName]; if (propertyData != null) { DateTime.TryParse(propertyData.ToString(), out DateTime dateValue); if (dateValue != DateTime.MinValue) { if (!string.IsNullOrEmpty(customTask.Type)) { customTask.Deadline = dateValue.ToString("dd MMMM HH:mm"); var days = DateTime.Now.CountDaysInRange(dateValue); if (days == 0) { customTask.WarningColor = "red"; } else if (days > 0 && days < warningDays) { customTask.WarningColor = "green"; } } else { customTask.Deadline = " - "; } } } } } //Get Notifications customTask = await GetNotifications(id, customTask, true); taskList.Add(customTask); } } taskList = SortColumns(sorting, taskList); return(taskList); }