public bool UpdateContentPosts(ContentPost contentPost) { var errorMessage = ""; try { if (contentPost == null) throw new ArgumentNullException("User"); using (var context = new ContentContext()) { int rc = context.SaveChanges(); return rc > 0 ? true : false; } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { errorMessage += Environment.NewLine + string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } throw new Exception(errorMessage, dbEx); } }
public IList<ContentPost> GetAllContentPosts(bool ShowNotPublished = false) { using (var context = new ContentContext()) { return context.ContentPosts.ToList<ContentPost>() .Where(bp => bp.IsValid(ShowNotPublished)).ToList(); } }
public ContentPost GetContentPostByID(int ID) { using (var context = new ContentContext()) { return context.ContentPosts.Where (u => (u.ID == ID) && u.IsValid(false) ).FirstOrDefault(); } }
public bool DeleteContentPosts(ContentPost contentPost) { using (var context = new ContentContext()) { context.ContentPosts.Remove(contentPost); int rc = context.SaveChanges(); return rc > 0 ? true : false; } }
public bool CreateContentPosts(ContentPost contentPost) { if (contentPost == null) throw new System.NullReferenceException("User cannot be Null"); try { using (var context = new ContentContext()) { // _contentPostRepository.Create(contentPost); context.ContentPosts.Add(contentPost); int rc = context.SaveChanges(); return rc > 0 ? true : false; } } catch { throw; } }
public IList<ContentComment> GetAllContentComment(bool ShowNotPublished = false) { using (var context = new ContentContext()) { return context.ContentComments .Where(b => b.IsValid(ShowNotPublished)).ToList(); } }