Exemple #1
0
        public override bool CreateBlogEntry(BlogEntry blogEntryToCreate)
        {
            // validation
            if (String.IsNullOrEmpty(blogEntryToCreate.Title))
            {
                _modelState.AddModelError("Title", "Title is required.");
            }
            /*if (blogEntryToCreate.Title.Length > 500)
            {
                _modelState.AddModelError("Title", "Title is too long.");
            }*/
            if (String.IsNullOrEmpty(blogEntryToCreate.Text))
            {
                _modelState.AddModelError("Text", "Text is required.");
            }
            if (_modelState.IsValid == false)
            {
                return false;
            }

                // Business Rules
            if (String.IsNullOrEmpty(blogEntryToCreate.Name))
            {
                blogEntryToCreate.Name = blogEntryToCreate.Title;
            }

                blogEntryToCreate.Name = blogEntryToCreate.Name.Replace(" ", "-");
                blogEntryToCreate.Name = Regex.Replace(blogEntryToCreate.Name,
                "[\"$&+,/:;=?@]", string.Empty);

                // Data access
                _blogRepository.CreateBlogEntry(blogEntryToCreate);
                return true;
        }
        public override bool CreateBlogEntry(BlogEntry blogEntryToCreate)
        {
            // validation
            if (blogEntryToCreate.Title.Trim().Length == 0)
                _modelState.AddModelError("Title", "Title is required.");
            if (blogEntryToCreate.Title.Length > 500)
                _modelState.AddModelError("Title", "Title is too long.");
            if (blogEntryToCreate.Text.Trim().Length == 0)
                _modelState.AddModelError("Text", "Text is required.");
            if (blogEntryToCreate.Author.Trim().Length == 0)
                _modelState.AddModelError("Author", "Author is required.");
            if (blogEntryToCreate.Description.Trim().Length == 0)
                _modelState.AddModelError("Description", "Description is required.");
            if (_modelState.IsValid == false)
                return false;

            // Business Rules
            if (String.IsNullOrEmpty(blogEntryToCreate.Name))
                blogEntryToCreate.Name = blogEntryToCreate.Title;
            blogEntryToCreate.Name = blogEntryToCreate.Name.Replace(" ", "-");
            blogEntryToCreate.Name = Regex.Replace(blogEntryToCreate.Name, "[\"$&+,/:;=?@]", string.Empty);

            if (blogEntryToCreate.DatePublished == DateTime.MinValue)
                blogEntryToCreate.DatePublished = DateTime.Now;

            // Data access
            _blogRepository.CreateBlogEntry(blogEntryToCreate);
            return true;
        }
 public static BlogEntry Get()
 {
     var blogEntry = new BlogEntry();
     blogEntry.Title = "Test Entry";
     blogEntry.Name = "Test Entry";
     blogEntry.Text = "Blog text";
     blogEntry.DatePublished = new DateTime(2010, 12, 25);
     return blogEntry;
 }
        public ActionResult Create(BlogEntry blogEntryToCreate)
        {
            //_blogEntries.Add(blogEntryToCreate);
            //return RedirectToAction("Index");

            // creating new blog entry
            _repository.CreateBlogEntry(blogEntryToCreate);
            return RedirectToAction("Index");
        }
 public static BlogEntry Get()
 {
     var blogEntry = new BlogEntry();
     blogEntry.Title = "Test Entry";
     blogEntry.Name = "Test Entry";
     blogEntry.Text = "Blog text";
     blogEntry.DatePublished = new DateTime(2010, 12, 25);
     blogEntry.Author = "Stephen";
     blogEntry.Description = "The Description";
     return blogEntry;
 }
        /// <summary>
        /// Creates a new comment for a blog entry.
        /// </summary>
        public static Comment CreateComment(CommentController commentController, BlogEntry blogEntry, string commentTitle, DateTime commentDatePublished)
        {
            // Create comment
            var commentToCreate = CommentFactory.Get();
            commentToCreate.BlogEntryId = blogEntry.Id;
            commentToCreate.Title = commentTitle;
            commentToCreate.DatePublished = commentDatePublished;

            // Add to blog entry
            commentController.Create(commentToCreate);

            return commentToCreate;
        }
        public void CreateBlogEntry()
        {
            // Arrange
            var repository = new FakeBlogRepository();
            var controller = new BlogController(repository);
            var blogEntryToCreate = new BlogEntry();

            // Act
            controller.Create(blogEntryToCreate);
            var result = (ViewResult)controller.Index();

            // Assert
            var firstEntry = ((IList)result.ViewData.Model)[0];
            Assert.AreSame(blogEntryToCreate, firstEntry);
        }
 public abstract bool CreateBlogEntry(BlogEntry blogEntryToCreate);
Exemple #9
0
 public abstract void CreateBlogEntry(BlogEntry blogEntryToCreate);
 public abstract void CreateBlogEntry(BlogEntry blogEntryToCreate);
 public override void CreateBlogEntry(BlogEntry blogEntryToCreate)
 {
     _blogEntries.Add(blogEntryToCreate);
 }
 public ActionResult Create(BlogEntry blogEntryToCreate)
 {
     _repository.CreateBlogEntry(blogEntryToCreate);
     return RedirectToAction("Index");
 }
 public static string BlogLink(this HtmlHelper helper, BlogEntry entry)
 {
     return helper.ActionLink(entry.Title, "Index", "Archive", new {year=entry.DatePublished.Year, month=entry.DatePublished.Month, day=entry.DatePublished.Day, name = entry.Name }, null);
 }
Exemple #14
0
 public abstract bool CreateBlogEntry(BlogEntry blogEntryToCreate);
 public static string BlogLink(this HtmlHelper helper, BlogEntry entry)
 {
     return helper.RouteLink(entry.Title, "Details", new { year = entry.DatePublished.Year, month = entry.DatePublished.Month, day = entry.DatePublished.Day, name = entry.Name });
 }
 public static string BlogLink(this HtmlHelper helper, BlogEntry entry)
 {
     return helper.ActionLink(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(entry.Title), "Index", "Archive", new { year = entry.DatePublished.Year, month = entry.DatePublished.Month, day = entry.DatePublished.Day, name = entry.Name }, null).ToHtmlString();
 }