
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.41 KB | hits: 10 | expires: Never
No data is saved in the DB and no errors is fired
public class Post
{
[Key]
public int PostID { get; set; }
...
public virtual ICollection<Tag> Tags { get; set; }
}
public class Tag
{
[Key]
public int TagID { get; set; }
[Required, StringLength(50)]
public string Name { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
Tag t = m_TagRepository.GetTag(tag.Trim().ToUpper());
if (t == null) t = new Tag { Name = tag.Trim().ToUpper() };
post.Tags.Add(t);
public void SavePost(Post post)
{
if (post.PostID == 0)
{
m_Context.Posts.Add(post);
}
else
{
var entry = m_Context.Entry(post);
entry.State = EntityState.Modified;
}
m_Context.SaveChanges();
}
[Authorize, HttpPost, ValidateInput(false), Theme("Admin")]
public ActionResult Edit(PostFullViewModel postToEdit)
{
if (!ModelState.IsValid)
return View();
Post post = Mapper.Map<PostFullViewModel, Post>(postToEdit);
m_PostBusiness.UpdateTags(post, postToEdit.TagString);
m_PostBusiness.SavePost(post);
TempData.SetStatusMessage(Strings.Post_SavedSuccessfully);
return RedirectToAction("Manage");
}
var post = GetPostFromYourRequest();
context.Posts.Attach(post);
ProcessTags(post, postToEdit);
context.SaveChanges();