Пример #1
0
        private async Task <T> GetUserCollectionOrCreateAsync()
        {
            var userOid = User.GetOid();

            var collection = await Store.GetCollectionAsync(userOid, userOid).ConfigureAwait(false);

            if (collection == null)
            {
                collection = await Store.StoreCollectionAsync(new Collection
                {
                    CollectionId = userOid,
                    PrincipalId  = userOid,
                    Name         = "Your Ideas",
                }).ConfigureAwait(false);

                await RoleStore.StoreRoleAssignmentAsync(new RoleAssignment
                {
                    CollectionId = userOid,
                    PrincipalId  = userOid,
                    Role         = RoleAssignment.Owner,
                }).ConfigureAwait(false);
            }

            return(Representer.ToView(collection));
        }
        public virtual async Task <ActionResult <T> > Replace(Guid collection, Guid user, [FromBody] T roleAssignment)
        {
            var role = await Store.GetRoleAssignment(collection, User.GetOid()).ConfigureAwait(false);

            if (role?.Role != RoleAssignment.Owner)
            {
                return(this.Forbid());
            }

            var model = Representer.ToModel(roleAssignment);

            model.CollectionId = collection;
            model.PrincipalId  = user;

            var added = await Store.StoreRoleAssignmentAsync(model).ConfigureAwait(false);

            return(Representer.ToView(added));
        }
Пример #3
0
 public virtual async Task <T> GetHealth() => Representer.ToView(await Store.GetHealthStateAsync().ConfigureAwait(false));
Пример #4
0
        public virtual async Task <ActionResult <T> > Add(T collection)
        {
            var model = Representer.ToModel(collection);

            if (model.CollectionId == Guid.Empty)
            {
                model.CollectionId = Guid.NewGuid();
            }

            model.PrincipalId = this.User.GetOid();

            if (string.IsNullOrEmpty(model.Name))
            {
                return(this.BadRequest());
            }

            var added = await Store.StoreCollectionAsync(model).ConfigureAwait(false);

            await RoleStore.StoreRoleAssignmentAsync(new RoleAssignment
            {
                CollectionId = added.CollectionId,
                PrincipalId  = added.PrincipalId,
                Role         = RoleAssignment.Owner
            }).ConfigureAwait(false);

            var area = this.RouteData.Values["area"];

            return(this.CreatedAtRoute($"GetCollection.{area}", new { id = added.CollectionId.ToString("N", CultureInfo.InvariantCulture) }, Representer.ToView(added)));
        }