【问题标题】:Link Products to user ID将产品链接到用户 ID
【发布时间】:2018-03-23 03:12:43
【问题描述】:

我正在使用 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; }





}

【问题讨论】:

  • 每个产品只有一个userid还是多个?
  • @ecKO 其允许程序根据当前用户过滤到一个用户可以拥有多个产品

标签: c# asp.net entity-framework-core ef-core-2.0


【解决方案1】:

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

那你就需要打电话了

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

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

【讨论】:

  • 您甚至没有正确阅读该类它所称的产品,我想将用户存储在其中
  • 我为这个错误道歉,然后你需要做Products.properyName = user。或者不要将其保存到名为 user 的变量中,而是直接将其存储到属性中。
  • 应该可以,考虑到我们所做的只是设置实体的属性。让我知道它是否有效。
  • 我想要的是一个解决方案,它会告诉脚手架然后以某种方式过滤用户,我认为这不会做到
  • 知道用户必须在问题页面上使用 [Authorise] 标记登录,难道你不能在模型上设置这个吗?。
猜你喜欢
  • 2011-12-06
  • 2019-05-15
  • 1970-01-01
  • 2018-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多