public static string NameLink(this HtmlHelper helper, Comment comment) { if (!String.IsNullOrEmpty(comment.Url)) { var tb = new TagBuilder("a"); tb.SetInnerText(comment.Name); tb.MergeAttribute("href", comment.Url); return tb.ToString(TagRenderMode.Normal); } return helper.Encode(comment.Name); }
public static Comment Get() { var commentToCreate = new Comment(); commentToCreate.BlogEntryId = 1; commentToCreate.Title = "New Comment"; commentToCreate.DatePublished = new DateTime(2010, 12, 25); commentToCreate.Url = "http://myblog.com"; commentToCreate.Name = "Bob"; commentToCreate.Email = "*****@*****.**"; commentToCreate.Text = "Here is the comment"; return commentToCreate; }
// Comment Methods public override bool CreateComment(Comment commentToCreate) { // Validation if (commentToCreate.Title.Trim().Length == 0) _modelState.AddModelError("Title", "Title is required."); if (commentToCreate.Name.Trim().Length == 0) _modelState.AddModelError("Name", "Name is required."); if (commentToCreate.Text.Trim().Length == 0) _modelState.AddModelError("Text", "Comment is required."); if (_modelState.IsValid == false) return false; // Business rules if (commentToCreate.DatePublished == DateTime.MinValue) commentToCreate.DatePublished = DateTime.Now; // Data access _blogRepository.CreateComment(commentToCreate); return true; }
// Comment methods public abstract bool CreateComment(Comment commentToCreate);
public override void CreateComment(Comment commentToCreate) { _comments.Add(commentToCreate); }
// Comment Methods public abstract void CreateComment(Comment commentToCreate);