public InventoryItem(NancyContext context, InventoryItemDto item)
            : base(context.Request.Url.ToString(), new [] { "item", "detail" })
        {
            Properties = new Dictionary <string, object>
            {
                { "Name", item.Name },
                { "Quantity", item.Quantity }
            };

            Links = new LinksFactory(context)
                    .With(new GetInventoryLink(), WithLink <GetInventoryLink> .Property(x => x.Title = "Back to inventory"))
                    .Build();

            Actions = new ActionsFactory(context)
                      .With(new AddInventoryItemQuantityAction(item.Id, item.Version),
                            WithAction <AddInventoryItemQuantityAction>
                            .Field(x => x.Version)
                            .Having(x => x.Type = "hidden"))
                      .With(new RemoveInventoryItemQuantityAction(item.Id, item.Version),
                            WithAction <RemoveInventoryItemQuantityAction>
                            .Field(x => x.Version)
                            .Having(x => x.Type = "hidden"))
                      .With(new RenameInventoryItemAction(item.Id, item.Version, item.Name),
                            WithAction <RenameInventoryItemAction>
                            .Field(x => x.Version)
                            .Having(x => x.Type = "hidden"))
                      .Build();
        }
示例#2
0
        public User(NancyContext context, Domain.User user) : base(context.Request.Url.ToString(), "user")
        {
            Properties = new Dictionary <string, object>
            {
                { "Username", user.Username },
                { "Claims", string.Join(", ", user.Claims.Select(x => x.ToString()).ToList()) }
            };

            Links = new LinksFactory(context).With(new GetUsers(), WithLink <GetUsers> .Property(x => x.Title = "Back to all users")).Build();

            Actions = new ActionsFactory(context).With(new PutClaims(user),
                                                       WithAction <PutClaims> .Field(x => x.Claims)
                                                       .Having(x => x.Type    = "select")
                                                       .Having(x => x.Options = GetClaimsOptions())).Build();
        }