/// <summary> /// Publishes a new document. /// </summary> /// <param name="doc">The IDocumentInfo for the document, including the document key.</param> /// <param name="text">The document's text.</param> public static void Publish(IDocumentInfo doc, string text) { using (var db = new Silversite.Context()) { var d = Current(db, doc.ContentKey); if (d == null) throw new ArgumentException("invalid key"); if (d.Text != string.Empty) db.Documents.Add(d.Old()); d.CopyFrom(doc); d.Text = text; db.SaveChanges(); } }
/// <summary> /// Sets the IDocumentInfo of the corresponding document in the database. /// </summary> /// <param name="doc">The IDocumentInfo of the document.</param> public static void Modify(IDocumentInfo doc) { using (var db = new Silversite.Context()) { var d = Current(db, doc.ContentKey); if (d == null) return; d.CopyFrom(doc); db.SaveChanges(); } }
/// <summary> /// sets the user's or role's persmission for a document or documentCategory /// </summary> /// <param name="userOrRole"></param> /// <param name="category"></param> /// <param name="a"></param> public static void Set(string userOrRole, string category, Permission a) { string categoryWithPermission; if (!(category.StartsWith("+") || category.StartsWith("-"))) categoryWithPermission = ((a == Permission.Allowed) ? "+" : "-") + category; else { categoryWithPermission = category; category = category.Substring(1); } using (var db = new Silversite.Context()) { var rights = db.EditRights.Find(userOrRole); if (rights != null) { var categoriesWithPermission = rights.DocumentCategories.SplitList<string>(s => s, ',', ';').ToList(); var categories = categoriesWithPermission.Select(c => (c.StartsWith("+") || c.StartsWith("-")) ? c.Substring(1) : c).ToList(); if (categories.Contains(category)) { categoriesWithPermission[categories.IndexOf(category)] = categoryWithPermission; } else { categoriesWithPermission.Add(categoryWithPermission); } rights.DocumentCategories = categoriesWithPermission.StringList("; "); } else { rights = new EditRights { UserOrRole= userOrRole, DocumentCategories = categoryWithPermission, IsUser = IsNameUser(db, userOrRole) }; db.EditRights.Add(rights); } db.SaveChanges(); } }
/// <summary> /// Creates a new document and returns the document key. /// </summary> /// <param name="path">The path of the .aspx page or control containing the document.</param> /// <returns></returns> public static IDocumentInfo Create(string path) { using (var db = new Silversite.Context()) { var doc = new Document { Author = null, Path = path, Domain = Domains.Current }; db.Documents.Add(doc); db.SaveChanges(); doc.ContentKey = doc.Key; doc.Revision = 1; return doc; } }
/// <summary> /// Sets the person's or the role's rights so they can edit the document or the document category. /// </summary> /// <param name="userOrRole">A user or a role.</param> /// <param name="documentCategories">A comma or semicolon separated list of documents or document categories.</param> public static void Set(string userOrRole, string documentCategories) { using (var db = new Silversite.Context()) { var rights = db.EditRights.Find(userOrRole); if (rights != null) { rights.DocumentCategories = documentCategories; } else { rights = new EditRights { UserOrRole= userOrRole, DocumentCategories = documentCategories, IsUser = IsNameUser(db, userOrRole) }; db.EditRights.Add(rights); } db.SaveChanges(); } }