public void SetTags(DocumentImportDTO documentDto, Webpage webpage) { List<string> tagsToAdd = documentDto.Tags.Where( s => !webpage.Tags.Select(tag => tag.Name).Contains(s, StringComparer.InvariantCultureIgnoreCase)) .ToList(); List<Tag> tagsToRemove = webpage.Tags.Where( tag => !documentDto.Tags.Contains(tag.Name, StringComparer.InvariantCultureIgnoreCase)).ToList(); foreach (string item in tagsToAdd) { Tag tag = GetExistingTag(item); bool isNew = tag == null; if (isNew) { tag = new Tag {Name = item}; _session.Transact(session => session.Save(tag)); } if (!webpage.Tags.Contains(tag)) webpage.Tags.Add(tag); if (!tag.Documents.Contains(webpage)) tag.Documents.Add(webpage); _session.Transact(session => session.Update(tag)); } foreach (Tag tag in tagsToRemove) { webpage.Tags.Remove(tag); tag.Documents.Remove(webpage); Tag closureTag = tag; _session.Transact(session => session.Update(closureTag)); } }
public IEnumerable<string> GetErrors(DocumentImportDTO item, IList<DocumentImportDTO> allItems) { var value = Selector(item); if (!String.IsNullOrWhiteSpace(value)) { if (value.Length > Length) yield return string.Format( "{0} is too long - max length is {1} characters and your value is {2} characters in length.", DisplayName, Length, value.Length); } }
public IEnumerable<string> GetErrors(DocumentImportDTO item, IList<DocumentImportDTO> allItems) { if (item.UrlHistory.Count <= 0) yield break; var document = _documentService.GetDocumentByUrl<Webpage>(item.UrlSegment); if (document == null) yield break; var urls = _urlHistoryService.GetAllOtherUrls(document).ToList(); foreach (var url in item.UrlHistory.Where(url => urls.Any(x => x.UrlSegment == url))) { yield return "One of url history segments is already within the system and belongs to another document."; } }
public void SetUrlHistory(DocumentImportDTO documentDto, Webpage webpage) { List<string> urlsToAdd = documentDto.UrlHistory.Where( s => !webpage.Urls.Select(history => history.UrlSegment) .Contains(s, StringComparer.InvariantCultureIgnoreCase)).ToList(); List<UrlHistory> urlsToRemove = webpage.Urls.Where( history => !documentDto.UrlHistory.Contains(history.UrlSegment, StringComparer.InvariantCultureIgnoreCase)) .ToList(); if (!urlsToAdd.Any() && !urlsToRemove.Any()) return; UpdateUrlHistories(webpage, urlsToAdd, urlsToRemove); }
private DocumentImportDTO GetDocumentImportDataTransferObject(ExcelWorksheet worksheet, int rowId, string name, ref List<string> parseErrors) { var item = new DocumentImportDTO(); item.ParentUrl = worksheet.GetValue<string>(rowId, 2); if (worksheet.GetValue<string>(rowId, 3).HasValue()) { item.DocumentType = worksheet.GetValue<string>(rowId, 3); item.UrlSegment = worksheet.GetValue<string>(rowId, 1).HasValue() ? worksheet.GetValue<string>(rowId, 1) : _webpageUrlService.Suggest(null, new SuggestParams { PageName = name, DocumentType = item.DocumentType }); } else parseErrors.Add("Document Type is required."); if (worksheet.GetValue<string>(rowId, 4).HasValue()) item.Name = worksheet.GetValue<string>(rowId, 4); else parseErrors.Add("Document Name is required."); item.BodyContent = worksheet.GetValue<string>(rowId, 5); item.MetaTitle = worksheet.GetValue<string>(rowId, 6); item.MetaDescription = worksheet.GetValue<string>(rowId, 7); item.MetaKeywords = worksheet.GetValue<string>(rowId, 8); item.Tags = GetTags(worksheet, rowId, parseErrors); if (worksheet.GetValue<string>(rowId, 10).HasValue()) { if (!worksheet.GetValue<string>(rowId, 10).IsValidInput<bool>()) parseErrors.Add("Reveal in Navigation is not a valid boolean value."); else item.RevealInNavigation = worksheet.GetValue<bool>(rowId, 10); } else item.RevealInNavigation = false; if (worksheet.GetValue<string>(rowId, 11).HasValue()) { if (!worksheet.GetValue<string>(rowId, 11).IsValidInput<int>()) parseErrors.Add("Display Order is not a valid number."); else item.DisplayOrder = worksheet.GetValue<int>(rowId, 11); } else item.DisplayOrder = 0; if (worksheet.GetValue<string>(rowId, 12).HasValue()) { if (!worksheet.GetValue<string>(rowId, 12).IsValidInput<bool>()) parseErrors.Add("Require SSL is not a valid boolean value."); else item.RequireSSL = worksheet.GetValue<bool>(rowId, 12); } else item.RequireSSL = false; if (worksheet.GetValue<string>(rowId, 13).HasValue()) { if (!worksheet.GetValue<string>(rowId, 13).IsValidInputDateTime()) parseErrors.Add("Publish Date is not a valid date."); else item.PublishDate = worksheet.GetValue<DateTime>(rowId, 13); } item.UrlHistory = GetUrlHistory(worksheet, rowId, parseErrors); return item; }
public IEnumerable<string> GetErrors(DocumentImportDTO item, IList<DocumentImportDTO> allItems) { if (string.IsNullOrWhiteSpace(item.DocumentType) || DocumentMetadataHelper.GetTypeByName(item.DocumentType) == null) yield return "Document Type is not valid MrCMS type."; }
public IEnumerable<string> GetErrors(DocumentImportDTO item, IList<DocumentImportDTO> allItems) { if (!string.IsNullOrWhiteSpace(item.ParentUrl) && _documentService.GetDocumentByUrl<Webpage>(item.ParentUrl) == null && !allItems.Any(x => x.UrlSegment == item.ParentUrl)) yield return "The parent url specified is not present within the system."; }