コード例 #1
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)));
        }
コード例 #2
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));
        }
コード例 #3
0
 public virtual async Task <ActionResult <T> > GetCollection(Guid?id)
 {
     if ((id ?? User.GetOid()) == User.GetOid())
     {
         return(await GetUserCollectionOrCreateAsync().ConfigureAwait(false));
     }
     return(Representer.ToViewOrDefault(await Store.GetCollectionAsync(User.GetOid(), id ?? User.GetOid()).ConfigureAwait(false)).ToActionResult() ?? this.NotFound());
 }
コード例 #4
0
      public ActionResult UpdateAgency(Representer rep)
      {
          var model = db.Representers.Find(rep.id);

          if (model == null)
          {
              HttpNotFound();
          }
          return(View("CreateNewAgency", model));
      }
コード例 #5
0
        public virtual async Task <ActionResult <T> > GetRoleAssignment(Guid collection, Guid user)
        {
            var role = await Store.GetRoleAssignment(collection, User.GetOid()).ConfigureAwait(false);

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

            return(Representer.ToViewOrDefault(await Store.GetRoleAssignment(user, collection).ConfigureAwait(false)).ToActionResult() ?? this.NotFound());
        }
コード例 #6
0
        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));
        }
コード例 #7
0
      public ActionResult CreateNewAgency(Representer representers)
      {
          if (representers.id == 0)
          {
              db.Representers.Add(representers);
          }
          else
          {
              var updateProperty = db.Representers.Find(representers.id);
              if (updateProperty == null)
              {
                  return(HttpNotFound());
              }

              updateProperty.name    = representers.name;
              updateProperty.surname = representers.surname;
              updateProperty.email   = representers.email;
              updateProperty.phone   = representers.phone;
          }


          db.SaveChanges();
          return(RedirectToAction("ListAgency"));
      }
コード例 #8
0
 public virtual async Task <T> GetHealth() => Representer.ToView(await Store.GetHealthStateAsync().ConfigureAwait(false));
コード例 #9
0
ファイル: Base.cs プロジェクト: yaml/Nyaml
 internal abstract Nodes.Base RepresentObject(object data, Representer representer);