コード例 #1
0
        // **************************************
        // 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;
            }
        }