public InitTemplatedPageRequest( string projectId, string createdByUserName, string author, NewContentViewModel model, ContentTemplate template ) { ProjectId = projectId; CreatedByUserName = createdByUserName; Author = author; ViewModel = model; Template = template; }
public NewContentViewModel Build(bool hideExplanation, DateTime sessionTimeSinceLastVisit) { var newContent = new NewContentViewModel(); var threads = _db.Threads.Where(thread => thread.Posts.Max(post => post.PostDate) > sessionTimeSinceLastVisit) .ToViewModels(true).ToList(); newContent.SessionTimeSinceLastVisit = sessionTimeSinceLastVisit; newContent.HideExplanation = hideExplanation; newContent.Threads = threads; newContent.NewContent = threads.Any(); return(newContent); }
public static bool TryBuild(this NewContentViewModel vm, TagResolver resolver, Domain domain, IEnumerable <MimeMapViewModel> mimes, ContentManager contentManager, out ContentItem item) { bool b = vm.Validate(); item = new ContentItem(); var contentType = vm.ContentType; if (b) { b = !b; item.Id = Guid.NewGuid().ToString().ToLower(); item.Display = vm.Display; item.Scope = vm.Scope; item.Properties.DefaultTags(domain); item.Properties.AddRange(resolver.Resolve(vm.Tags)); if (vm.HasFile) { FileInfo info = new FileInfo(vm.Filepath); if (contentManager.TryInload(info, out string filename)) { item.Mime = mimes.Resolve(info); item.Body = filename; item.Properties.Add(new Property() { Name = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.Extension}", Value = item.Mime }); var filetype = item.Mime.Trim(new char[] { '.' }); vm.Paths.Add($"/files/{filetype}"); b = true; } } else { item.Mime = vm.Mime; if (vm.IsLink) { if (!vm.Body.StartsWithAny(new string[] { "http://", "https://" })) { item.Body = $"http://{vm.Body}"; } else { item.Body = vm.Body; } } else if (vm.Body.Length > contentManager.MaxLength && contentManager.TryInloadAsFile(vm.Body, item.Id, out string filename, out FileInfo info)) { item.Mime = mimes.Resolve(info); item.Body = filename; item.Properties.Add(new Property() { Name = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.Extension}", Value = item.Mime }); b = true; } else { item.Body = vm.Body; } b = true; }