// **************************************
        // CreateCatalog
        // **************************************
        public static int CreateCatalog(Catalog catalog)
        {
            using (var ctx = new SongSearchContext()) {
                var cat = ctx.GetCatalog(catalog.CatalogName);
                var user = Account.User();

                if (cat == null) {

                    cat = new Catalog { CatalogName = catalog.CatalogName };
                    ctx.Catalogs.AddObject(cat);

                    ctx.SaveChanges();

                    UserManagementService.UpdateUserCatalogRole(user.UserId, cat.CatalogId, (int)Roles.Admin);

                } else if (!user.IsAtLeastInCatalogRole(Roles.Admin, cat.CatalogId)) {
                    throw new AccessViolationException("You do not have admin rights to this catalog");
                }

                return cat.CatalogId;
            }
        }
 /// <summary>
 /// Create a new Catalog object.
 /// </summary>
 /// <param name="catalogId">Initial value of the CatalogId property.</param>
 /// <param name="catalogName">Initial value of the CatalogName property.</param>
 /// <param name="createdByUserId">Initial value of the CreatedByUserId property.</param>
 /// <param name="createdOn">Initial value of the CreatedOn property.</param>
 public static Catalog CreateCatalog(global::System.Int32 catalogId, global::System.String catalogName, global::System.Int32 createdByUserId, global::System.DateTime createdOn)
 {
     Catalog catalog = new Catalog();
     catalog.CatalogId = catalogId;
     catalog.CatalogName = catalogName;
     catalog.CreatedByUserId = createdByUserId;
     catalog.CreatedOn = createdOn;
     return catalog;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Catalogs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCatalogs(Catalog catalog)
 {
     base.AddObject("Catalogs", catalog);
 }
Beispiel #4
0
 public static bool IsAtLeastInCatalogRole(this User user, Roles role, Catalog catalog)
 {
     return user != null &&  (user.IsSuperAdmin() ||
         (user.UserCatalogRoles != null ?
         user.UserCatalogRoles.Any(x => x.CatalogId == catalog.CatalogId && x.RoleId <= (int)role) :
         false));
 }
Beispiel #5
0
        public static Contact GetCatalogContactInfo(this User user, Catalog catalog, bool checkParent = true)
        {
            if (user == null) { return null; }

            // Pluggers and above can set up their own contact info, everyone else inherits down
            if (user.IsPlanOwner &&
                user.PricingPlan != null &&
                user.PricingPlan.CustomContactUs &&
                user.IsAtLeastInCatalogRole(Roles.Admin, catalog)
                ) {

                return user.Contacts.FirstOrDefault(c => c.IsDefault);

            } else if (checkParent && user.ParentUserId.HasValue) {
                var parent = User(user.ParentUserId.Value);
                return parent.GetCatalogContactInfo(catalog);

            } else return null;
        }