public static BlogPostViewModelExtender ToServiceModel(this SaveBlogPostPropertiesModel model) { var serviceModel = new BlogPostViewModelExtender(); serviceModel.Version = model.Version; serviceModel.Title = model.Title; serviceModel.IntroText = model.IntroText; serviceModel.Content = model.HtmlContent; serviceModel.LiveFromDate = model.ActivationDate; serviceModel.LiveToDate = model.ExpirationDate; serviceModel.BlogUrl = model.BlogPostUrl; serviceModel.AuthorId = model.AuthorId; serviceModel.CategoryId = model.CategoryId; serviceModel.DesirableStatus = model.IsPublished ? ContentStatus.Published : ContentStatus.Draft; serviceModel.Tags = model.Tags; serviceModel.Image = new ImageSelectorViewModel { ImageId = model.MainImageId }; serviceModel.FeaturedImageId = model.FeaturedImageId; serviceModel.SecondaryImageId = model.SecondaryImageId; serviceModel.IsArchived = model.IsArchived; serviceModel.PublishedOn = model.PublishedOn; serviceModel.LayoutId = model.LayoutId; serviceModel.MasterPageId = model.MasterPageId; serviceModel.ContentId = model.TechnicalInfo != null && model.TechnicalInfo.BlogPostContentId.HasValue ? model.TechnicalInfo.BlogPostContentId.Value : Guid.Empty; serviceModel.PageContentId = model.TechnicalInfo != null && model.TechnicalInfo.PageContentId.HasValue ? model.TechnicalInfo.PageContentId.Value : (Guid?)null; serviceModel.RegionId = model.TechnicalInfo != null && model.TechnicalInfo.RegionId.HasValue ? model.TechnicalInfo.RegionId.Value : (Guid?)null; serviceModel.UseCanonicalUrl = model.UseCanonicalUrl; serviceModel.UseNoFollow = model.UseNoFollow; serviceModel.UseNoIndex = model.UseNoIndex; serviceModel.MetaKeywords = model.MetaData != null ? model.MetaData.MetaKeywords : null; serviceModel.MetaDescription = model.MetaData != null ? model.MetaData.MetaDescription : null; serviceModel.MetaTitle = model.MetaData != null ? model.MetaData.MetaTitle : null; if (model.Language != null) { serviceModel.UpdateLanguage = true; serviceModel.LanguageGroupIdentifier = model.Language.LanguageGroupIdentifier; serviceModel.LanguageId = model.Language.Id; } if (model.AccessRules != null) { serviceModel.AccessRules = model.AccessRules .Select(r => (IAccessRule) new UserAccessViewModel { AccessLevel = (AccessLevel)(int)r.AccessLevel, Identity = r.Identity, IsForRole = r.IsForRole }) .ToList(); } return(serviceModel); }
private static SaveBlogPostPropertiesModel MapBlogPostModel(GetBlogPostPropertiesResponse response) { var model = new SaveBlogPostPropertiesModel { Version = response.Data.Version, BlogPostUrl = response.Data.BlogPostUrl, Title = response.Data.Title, IntroText = response.Data.IntroText, IsPublished = response.Data.IsPublished, PublishedOn = response.Data.PublishedOn, LayoutId = response.Data.LayoutId, MasterPageId = response.Data.MasterPageId, Categories = response.Data.Categories, AuthorId = response.Data.AuthorId, MainImageId = response.Data.MainImageId, FeaturedImageId = response.Data.FeaturedImageId, SecondaryImageId = response.Data.SecondaryImageId, ActivationDate = response.Data.ActivationDate, ExpirationDate = response.Data.ExpirationDate, IsArchived = response.Data.IsArchived, UseCanonicalUrl = response.Data.UseCanonicalUrl, UseNoFollow = response.Data.UseNoFollow, UseNoIndex = response.Data.UseNoIndex, HtmlContent = response.HtmlContent, OriginalText = response.OriginalText, ContentTextMode = response.ContentTextMode ?? ContentTextMode.Html, MetaData = response.MetaData, Language = response.Language, TechnicalInfo = response.TechnicalInfo, AccessRules = response.AccessRules, ChildContentsOptionValues = response.ChildContentsOptionValues }; if (response.Tags != null) { model.Tags = response.Tags.Select(t => t.Name).ToList(); } return(model); }