C# 将产品链接到用户ID

C# 将产品链接到用户ID,c#,asp.net,entity-framework-core,ef-core-2.0,C#,Asp.net,Entity Framework Core,Ef Core 2.0,我正在使用asp.net identity,我有一个名为Products的类,但我想能够做的是将产品链接到用户,我将如何添加到一个列中,该列将根据产品存储身份的活动登录用户。顺便说一句,我主要是使用脚手架来生产我的积垢,所以我希望有一种方法可以与之相比 Obv我使用的是identity core,只需要知道如何添加正确的字段以使其存储用户Id 我还需要做的是,管理员组中的任何人都会显示所有产品,但当它是用户时,它只会显示他们创建的产品 public class Products { [K

我正在使用asp.net identity,我有一个名为Products的类,但我想能够做的是将产品链接到用户,我将如何添加到一个列中,该列将根据产品存储身份的活动登录用户。顺便说一句,我主要是使用脚手架来生产我的积垢,所以我希望有一种方法可以与之相比

Obv我使用的是identity core,只需要知道如何添加正确的字段以使其存储用户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; }





}

那么,您应该在person类中创建一个用户属性,该属性存储值(以及get和set)

那你就需要打电话了

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

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

那么,您应该在person类中创建一个用户属性,该属性存储值(以及get和set)

那你就需要打电话了

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

在课堂上,你在做你的逻辑,将此
user
变量存储到您在Products类中创建的user属性中时。

每个产品只有一个或多个用户ID?@ecKO-its允许程序基于当前用户进行筛选,而一个用户可以有多个产品每个产品只有一个或多个用户ID?@ecKO-its允许程序基于当前用户对一个用户可以有多个产品您甚至没有正确读取该类及其调用的产品,我想将该用户存储在该类中我为错误道歉,然后您需要执行
products.properyName=user
。或者,与其将其保存到名为user的变量中,不如直接将其存储到属性中。考虑到我们所做的只是设置实体的属性,它应该这样做。让我知道它是否有效。我想要的是一个解决方案,该解决方案将告诉脚手架,然后以某种方式对用户进行过滤。我认为这样做行不通。您能否在知道用户必须使用[授权]登录的情况下,在模型上设置此选项在quesiton?中的页面上标记。您甚至没有正确阅读类及其调用的产品,我想将用户存储在其中。我为错误道歉,然后您需要执行
products.properyName=user
。或者,与其将其保存到名为user的变量中,不如直接将其存储到属性中。考虑到我们所做的只是设置实体的属性,它应该这样做。让我知道它是否有效。我想要的是一个解决方案,它将告诉脚手架,然后以某种方式过滤用户。我不认为这会起作用。你可以不在模型上设置它,因为知道用户将不得不使用quesiton?页面上的[授权]标签登录?。