Skip to content
Permalink
Browse files

Fix display issues when accessing posts saved with the old model stru…

…cture.
  • Loading branch information
jrusbatch committed Feb 9, 2013
1 parent 99b0f9e commit a6ec6ab6cd67b51825a3cfc4315eba3c50c8147a
Showing with 87 additions and 18 deletions.
  1. +68 −3 Core/Models/Post.cs
  2. +2 −2 LanguageServices/Document.cs
  3. +2 −2 Web/Models/PostViewModel.cs
  4. +4 −4 Web/Queries/SamplePostQuery.cs
  5. +11 −7 Web/Views/Home/Show.cshtml
@@ -7,10 +7,16 @@ namespace Compilify.Models
public class Post : ICodeProject
{
private ICollection<Document> documents;
private ICollection<string> tags;

public Post()
{
documents = new HashSet<Document>();
tags = new HashSet<string>();
documents = new HashSet<Document>
{
new Document("Content", string.Empty),
new Document("Classes", string.Empty)
};
}

public string Id { get; set; }
@@ -19,6 +25,44 @@ public Post()

public int Version { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public IEnumerable<string> Tags
{
get { return tags; }
set { tags = new HashSet<string>(value ?? Enumerable.Empty<string>()); }
}

public string Content
{
get
{
var doc = GetOrCreateDocument("Content");
return doc != null ? doc.Text : string.Empty;
}
set
{
var doc = GetOrCreateDocument("Content");
doc.Text = value;
}
}

public string Classes
{
get
{
var doc = GetOrCreateDocument("Classes");
return doc != null ? doc.Text : string.Empty;
}
set
{
var doc = GetOrCreateDocument("Classes");
doc.Text = value;
}
}

string ICodeProject.Name
{
get { return "Untitled"; }
@@ -48,13 +92,34 @@ public IEnumerable<Document> Documents
set { documents = new HashSet<Document>(value ?? Enumerable.Empty<Document>()); }
}

public void AddDocument(string name, string text)
public void AddOrUpdateDocument(string name, string text)
{
documents.Add(new Document(name, text));
var doc = documents.FirstOrDefault(x => x.Name == name);

if (doc != null)
{
doc.Text = text;
}
else
{
documents.Add(new Document(name, text));
}
}

/// <summary>
/// The UTC date and time that the post was first persisted to the data store.</summary>
public DateTime? Created { get; set; }

private Document GetOrCreateDocument(string name)
{
var document = documents.FirstOrDefault(x => x.Name == name);

if (document == null)
{
documents.Add(document = new Document(name, string.Empty));
}

return document;
}
}
}
@@ -13,10 +13,10 @@ public Document(string name, string text)
}

[DataMember(Order = 1)]
public string Name { get; private set; }
public string Name { get; set; }

[DataMember(Order = 2)]
public string Text { get; private set; }
public string Text { get; set; }

public string GetText()
{
@@ -38,7 +38,7 @@ public static PostViewModel Create(Post post)
public string Slug { get; set; }

public int Version { get; set; }

public Guid? AuthorId { get; set; }

public IEnumerable<DocumentModel> Documents { get; set; }
@@ -55,7 +55,7 @@ public Post ToPost()

foreach (var doc in Documents)
{
post.AddDocument(doc.Name, doc.Text);
post.AddOrUpdateDocument(doc.Name, doc.Text);
}

return post;
@@ -38,14 +38,14 @@ public Task<PostViewModel> Execute()
.AppendLine(" }")
.AppendLine("}");

post.AddDocument("Classes", builder.ToString());
post.Classes = builder.ToString();

builder.Clear()
.AppendLine("var person = new Person(name: null);")
.AppendLine()
.AppendLine("return person.Greet();");

post.AddDocument("Content", builder.ToString());
.AppendLine("return person.Greet();");

post.Content = builder.ToString();

var result = PostViewModel.Create(post);

@@ -10,14 +10,18 @@
</div>

<div id="editors">
@foreach(var document in Model.Documents)
{
<div class="editor-container">
<div class="editor">
<textarea data-name="@document.Name">@document.Text</textarea>
</div>
<div class="editor-container">
<div id="define" class="editor">
@{ var classes = Model.Documents.FirstOrDefault(x => x.Name == "Classes"); }
<textarea data-name="@classes.Name">@classes.Text</textarea>
</div>
}
</div>
<div class="editor-container">
<div id="execute" class="editor">
@{ var content = Model.Documents.FirstOrDefault(x => x.Name == "Content"); }
<textarea data-name="@content.Name">@content.Text</textarea>
</div>
</div>
</div>

<div id="footer">

0 comments on commit a6ec6ab

Please sign in to comment.
You can’t perform that action at this time.