public List <ContentModel.SavedDraft> FetchDrafts() { var userId = CurrentDatabase.UserId; var currentRoleIds = CurrentDatabase.CurrentRoleIds(); return(drafts ?? (drafts = (from c in CurrentDatabase.Contents where ContentTypeCode.EmailDrafts.Contains(c.TypeID) let u = CurrentDatabase.Users.First(vv => vv.UserId == c.OwnerID) let r = CurrentDatabase.Roles.FirstOrDefault(vv => vv.RoleId == c.RoleID) let isshared = (from tt in CurrentDatabase.Tags where tt.Name == "SharedDrafts" where tt.PersonOwner.Users.Any(uu => uu.UserId == c.OwnerID) where tt.PersonTags.Any(vv => vv.PeopleId == CurrentDatabase.UserPeopleId) select tt.Id).Any() where c.RoleID == 0 || c.OwnerID == userId || currentRoleIds.Contains(c.RoleID) orderby(c.OwnerID == userId ? 1 : 0) descending, c.Name select new ContentModel.SavedDraft() { created = c.DateCreated, id = c.Id, name = c.Name, shared = isshared, owner = u.Person.Name, ownerID = c.OwnerID, role = r.RoleName, roleID = c.RoleID, isUnlayer = c.TypeID == ContentTypeCode.TypeUnlayerSavedDraft }).ToList())); }
public ActionResult Embed(string id, bool preview = false) { try { var widget = new DashboardWidgetModel(id, CurrentDatabase); if (preview == true || widget.CacheHours == 0) { widget.CachePolicy = DashboardWidgetModel.CachePolicies.NeverCache.ToInt(); } if (widget.CachePolicy != DashboardWidgetModel.CachePolicies.NeverCache.ToInt()) { Response.SetCacheMinutes(widget.CacheHours * 60); } if (!widget.Roles.Intersect(CurrentDatabase.CurrentRoleIds()).Any()) { throw new Exception("Not authorized"); } string html = widget.Embed(); return(Content(html, "text/html")); } catch (Exception e) { return(Content("Error: " + e.Message)); } }
public IQueryable <Content> FetchTemplates() { var currentRoleIds = CurrentDatabase.CurrentRoleIds(); var isadmin = HttpContextFactory.Current.User.IsInRole("Admin"); return(from i in CurrentDatabase.Contents where ContentTypeCode.EmailTemplates.Contains(i.TypeID) where isadmin || i.RoleID == 0 || currentRoleIds.Contains(i.RoleID) orderby i.Name select i); }