将模型列表添加到Asp.net标识
我想根据MVC5中的身份模型为特定客户机分配一个商店列表。我希望能够使用MVC5示例代码中的默认注册来注册用户/客户机,并且能够添加存储,然后将存储分配给用户 我无法创建将idenity模型与新列表合并在一起的工作视图模型 以下是我到目前为止的情况: 型号:将模型列表添加到Asp.net标识,asp.net,asp.net-mvc-5,asp.net-identity,Asp.net,Asp.net Mvc 5,Asp.net Identity,我想根据MVC5中的身份模型为特定客户机分配一个商店列表。我希望能够使用MVC5示例代码中的默认注册来注册用户/客户机,并且能够添加存储,然后将存储分配给用户 我无法创建将idenity模型与新列表合并在一起的工作视图模型 以下是我到目前为止的情况: 型号: public class ApplicationUser : IdentityUser { //[Required] [Display(Name = "Client/Company Name")]
public class ApplicationUser : IdentityUser
{
//[Required]
[Display(Name = "Client/Company Name")]
public string ClientName { get; set; }
public List<Store> Stores { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
门店类别:
public class Store
{
public int Id { get; set; }
//public int ClientId { get; set; }
[Display(Name = "Client Name")]
public string ClientName { get; set; }
[Display(Name = "Store Name")]
public string Brand { get; set; }
[Display(Name = "Store Number")]
public string StoreNumber { get; set; }
[Display(Name="Store Login URL")]
public string LoginURL { get; set; }
}
最后,我的viewmodel:
public class ClientStoreViewModel
{
public ApplicationUser Users { get; set; }
public Store Stores { get; set; }
public ClientStoreViewModel()
{
Stores = new Store();
Users = new ApplicationUser();
}
}
你能分享商店类吗?@Daniel请看我的编辑。谢谢你的数据库设计。为什么有clientname店内模式?如果存储只有一个客户端,请为ApplicationUser添加导航属性。第二,您不需要连接,只需从db.Users.Include(“Stores”)中的c获取父(ApplicationUser)和子(Stores):var clients=即可。然后将此视图所需的ApplicationUser属性上移一级。我还建议AutoMapper将实体映射到您的ViewModel中。@SteveGreene谢谢。将ApplicationUser属性向上移动是什么意思?我应该使用applicationuser属性和store属性创建viewmodel吗?仅供参考,我将clientname作为stores的一部分,因为我有一个单独的clientname表,可以工作,但它没有链接到注册模型。我已经把它拿走了。非常感谢。选择用于该视图的实体模型属性,如果需要,对其进行注释,然后使用automapper之类的工具轻松地将其移回更新。
public class Store
{
public int Id { get; set; }
//public int ClientId { get; set; }
[Display(Name = "Client Name")]
public string ClientName { get; set; }
[Display(Name = "Store Name")]
public string Brand { get; set; }
[Display(Name = "Store Number")]
public string StoreNumber { get; set; }
[Display(Name="Store Login URL")]
public string LoginURL { get; set; }
}
public class ClientStoreViewModel
{
public ApplicationUser Users { get; set; }
public Store Stores { get; set; }
public ClientStoreViewModel()
{
Stores = new Store();
Users = new ApplicationUser();
}
}