1

我正在使用 asp.net 身份,我有一个名为 Products 的类,但我想做的是将产品链接到用户,我将如何添加一个列来存储身份的活动登录用户产品。顺便说一句,我主要使用脚手架来生产我的杂物,所以想要一个带有这个的方式比较表。

Obv 我正在使用身份核心,只需要不知道如何添加正确的字段来让它存储用户 ID。

我还需要发生的是管理员组中的任何人,然后它会显示所有产品,但是当它是用户时,它只会显示他们创建的产品?

public class Products
{
    [Key]
    public int ProductId { get; set; }

    public string ProductName { get; set; }

    public string ShotDescription { get; set; }

    public decimal OldPrice { get; set; }

    public decimal NewPrice { get; set; }

    public bool DisableBuyButton { get; set; }

    public bool DisableWishListButton { get; set; }

    public bool ShowForPrice { get; set; }


    public bool NotReturnable { get; set; }

    public int MinimumCartQty { get; set; }

    public int MaximumCartQty { get; set; }

    public string SKU { get; set; }


    public bool ShippingEnabled { get; set; }

    public decimal Weight { get; set; }

    public decimal Length { get; set; }

    public decimal Width { get; set; }

    public decimal Height { get; set; }

    public string Categories { get; set; }

    public string ManufacturerPartNumber        { get; set; }

    public DateTime AvailableDate { get; set; }

    public DateTime AvailableEndDate { get; set; }

    public string AdminComment { get; set; }

    public DateTime CreatedOn { get; set; }

    public DateTime UpdatedOn { get; set; }


    public Boolean DisplayAvailability { get; set; }

    public DateTime ExpectedDateBackOnStock { get; set; }

    public bool IsOnBackOrder { get; set; }

    public int Warehouse { get; set; }

    public int BinNumber { get; set; }

    public int IlseNumber { get; set; }



    public bool IsGiftCard { get; set; }

    public bool IsDownloadableProduct { get; set; }

    public bool IsRental { get; set; }


    public string SeoDescription { get; set; }


    public int   Stock { get; set; }

    public int PropertyImageId { get; set; }





}
4

1 回答 1

0

好吧,您应该在您的 person 类中创建一个 User 属性,该属性存储值(以及 get 和 set)。

然后你需要打电话

    var user = UserManager.FindById(User.Identity.GetUserId());

在您正在执行逻辑的类中,同时将此user变量存储到您在 Products 类中创建的 User 属性中。

于 2017-10-11T12:41:03.313 回答