public static void Validate(Models.Blog blog, Models.BlogEntry entry) { if (blog == null || string.IsNullOrEmpty(entry.Url)) { throw new Exception(CoreServices.Localization.GetExceptionText("InvalidResource.Error", "{0} is invalid.", "Blog Entry")); } else if (blog.Entries.Exists(e => e.Url.Equals(entry.Url, StringComparison.InvariantCultureIgnoreCase) && e.Id != entry.Id)) { throw new Exception(CoreServices.Localization.GetExceptionText("DuplicateResource.Error", "{0} already exists. Duplicates Not Allowed.", "Blog Entry")); } }
public static Models.BlogEntry SaveEntry(string blogId, Models.BlogEntry entry, string userId = null) { userId = string.IsNullOrEmpty(userId) ? CoreServices.Account.CurrentIdentityName : userId; var blog = Services.Blog.GetById(blogId); Validate(blog, entry); //parse out tags //entry.Tags = entry.Tags.SelectMany(t => t.Split(' ')).ToList(); if (string.IsNullOrEmpty(entry.Id)) { entry.Id = Guid.NewGuid().ToString(); //could use numbers here.. as only needs to be unique among this blog... blog.Entries.Add(entry); } else { var index = blog.Entries.FindIndex(e => e.Id == entry.Id); blog.Entries[index] = entry; } Save(blog, userId); return(entry); }