Example #1
0
        public void Save(Entry entry)
        {
            if (string.IsNullOrWhiteSpace(entry.Slug))
                throw new ArgumentNullException("entry", "Entry must have a Slug value to Save()");

            entry.Slug = entry.Slug.ToLowerInvariant();

            if (entry.DateCreated == default(DateTime))
            {
                var isUpdate = _repository.Exists<Entry>(entry.Slug);
                if (isUpdate)
                {
                    var oldEntry = _repository.Single<Entry>(entry.Slug);
                    entry.DateCreated = oldEntry.DateCreated;                    
                }
                else
                {
                    entry.DateCreated = DateTime.Now;
                }
            }

            entry.Author = _userService.Current.FriendlyName;

            _repository.Save(entry);
        }
Example #2
0
        public ActionResult Add(EditModel model)
        {
            var slug = model.Title.ToUrlSlug();

            // (these fields are hidden when creating a new entry, so don't validate them)
            ModelState["NewSlug"].Errors.Clear();
            ModelState["Date"].Errors.Clear();

            if (Services.Entry.Exists(slug))
                ModelState.AddModelError("Title", "Sorry, a post already exists with the slug '" + slug + "', please change the title.");

            if (!ModelState.IsValid)
                return View("Edit", model);

            var entry = new Entry
            {
                Title = model.Title,
                Markdown = model.Markdown,
                Slug = slug,
                Author = Services.User.Current.FriendlyName,
                DateCreated = DateTime.Now,
                IsPublished = false
            };

            Services.Entry.Save(entry);

            return RedirectToAction("Show", "Entry", new { id = entry.Slug });
        }
 public static HomeController.EntrySummaryModel Convert(Entry entry)
 {
     return new HomeController.EntrySummaryModel()
                {
                    Key = entry.Slug,
                    Title = entry.Title,
                    Date = entry.DateCreated.ToDateString(),
                    PrettyDate = entry.DateCreated.ToPrettyDate(),
                    IsPublished = entry.IsPublished ?? true
                };
 }
Example #4
0
        public void Single_Should_Return_Correct_Entity_By_Key()
        {
            // arrange
            const string title = "Top 10 C# Tips";
            var entry = new Entry { Title = title };
            var jsonRepository = new JsonRepository(TestContext.TestDir);

            // act
            jsonRepository.Save(entry);
            var retrievedEntry = jsonRepository.Single<Entry>("top-10-c-tips");

            // assert
            Assert.AreEqual(retrievedEntry.Title, title);
        }
Example #5
0
        public void Single_Should_Return_Correct_Entity_By_Key()
        {
            // arrange
            var repository = Instance;
            const string title = "Top 10 C# Tips";
            var slug = title.ToUrlSlug();
            var entry = new Entry { Slug = slug, Title = title, DateCreated = DateTime.Now };

            // act
            repository.Save(entry);

            var keyValue = Keys.GetKeyValue(entry);
            var retrievedEntry = repository.Single<Entry>(keyValue);

            // assert
            Assert.AreEqual(retrievedEntry.Title, title);
        }