public void RemoveAuthor(String blogEntryGuid, String authorEmail) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ BlogEntryAuthorLINQ blogEntryAuthorLinq = db.BlogEntryAuthors.SingleOrDefault(p => p.AuthorId == authorLinq.AuthorId && p.BlogEntryId == blogEntryLinq.BlogEntryId); if (blogEntryAuthorLinq == null) { db.BlogEntryAuthors.DeleteOnSubmit(blogEntryAuthorLinq); db.SubmitChanges(); } } }
public void ApplyAuthor(String blogEntryGuid, String authorEmail) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ if (!db.BlogEntryAuthors.Any(p => p.AuthorId == authorLinq.AuthorId && p.BlogEntryId == blogEntryLinq.BlogEntryId)) { BlogEntryAuthorLINQ blogEntryAuthorLinq = new BlogEntryAuthorLINQ(); blogEntryAuthorLinq.AuthorId = authorLinq.AuthorId; blogEntryAuthorLinq.BlogEntryId = blogEntryLinq.BlogEntryId; //+ db.BlogEntryAuthors.InsertOnSubmit(blogEntryAuthorLinq); db.SubmitChanges(); } } }
public String PostBlogEntry(String blogGuid, List <Author> authorList, String title, String content, DateTime dateTime, String blogEntryTypeGuid, List <Label> labelList, Boolean publish) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); BlogEntryTypeLINQ blogEntryTypeLinq = null; if (!String.IsNullOrEmpty(blogEntryTypeGuid)) { Validator.EnsureBlogEntryTypeExists(blogEntryTypeGuid, out blogEntryTypeLinq, db); } if (authorList == null) { authorList = new List <Author>(); } List <AuthorLINQ> authorLinqList; Validator.EnsureEachAuthorExists(authorList, out authorLinqList, db); if (labelList == null) { labelList = new List <Label>(); } List <LabelLINQ> labelLinqList; Validator.EnsureEachLabelExists(labelList, out labelLinqList, db); Validator.IsNotZero(authorLinqList.Count, "At least one author is required."); //+ using (TransactionScope scope = new TransactionScope()) { BlogEntryLINQ blogEntryLinq = new BlogEntryLINQ(); blogEntryLinq.BlogId = blogLinq.BlogId; blogEntryLinq.BlogEntryTitle = title; blogEntryLinq.BlogEntryTypeId = 1; blogEntryLinq.BlogEntryText = content; if (!String.IsNullOrEmpty(blogEntryTypeGuid)) { blogEntryLinq.BlogEntryTypeId = blogEntryTypeLinq.BlogEntryTypeId; } blogEntryLinq.BlogEntryStatus = db.BlogEntryStatus.SingleOrDefault(p => p.BlogEntryStatusId == (publish ? 1 : 3)); blogEntryLinq.BlogEntryCommentAllowStatus = db.BlogEntryCommentAllowStatus.SingleOrDefault(p => p.BlogEntryCommentAllowStatusId == 1); blogEntryLinq.BlogEntryGuid = Themelia.GuidCreator.GetNewGuid(); if (dateTime.Year >= 1950) { blogEntryLinq.BlogEntryPostDateTime = dateTime; } else { blogEntryLinq.BlogEntryPostDateTime = DateTime.Now; } blogEntryLinq.BlogEntryModifyDateTime = DateTime.Now; //+ db.BlogEntries.InsertOnSubmit(blogEntryLinq); db.SubmitChanges(); //+ BlogEntryUrlMappingLINQ blogEntryUrlMappingLinq = new BlogEntryUrlMappingLINQ(); blogEntryUrlMappingLinq.BlogEntryId = blogEntryLinq.BlogEntryId; blogEntryUrlMappingLinq.BlogEntryUrlMappingName = BlogEntryHelper.BuildBlogEntryLink(blogEntryLinq.BlogEntryPostDateTime, CreateBlogEntryPostUrlMapping(title)); blogEntryUrlMappingLinq.BlogEntryUrlMappingPrimary = true; db.BlogEntryUrlMappings.InsertOnSubmit(blogEntryUrlMappingLinq); //+ db.SubmitChanges(); //+ label foreach (LabelLINQ labelLinq in labelLinqList) { LabelBlogEntryLINQ labelBlogEntryLinq = new LabelBlogEntryLINQ(); labelBlogEntryLinq.BlogEntryId = blogEntryLinq.BlogEntryId; labelBlogEntryLinq.LabelId = labelLinq.LabelId; //+ db.LabelBlogEntries.InsertOnSubmit(labelBlogEntryLinq); } db.SubmitChanges(); //+ author foreach (AuthorLINQ authorLinq in authorLinqList) { BlogEntryAuthorLINQ blogEntryAuthorLinq = new BlogEntryAuthorLINQ(); blogEntryAuthorLinq.BlogEntryId = blogEntryLinq.BlogEntryId; blogEntryAuthorLinq.AuthorId = authorLinq.AuthorId; //+ db.BlogEntryAuthors.InsertOnSubmit(blogEntryAuthorLinq); } db.SubmitChanges(); //+ scope.Complete(); //+ return(blogEntryLinq.BlogEntryGuid); } } }