如何从管理配置文件页面为Asp.Net core 2.1中的ApplicationUser使用扩展模型?

时间:2019-06-03 21:20:23

标签: c# asp.net asp.net-core

我有一个Customer类和Employee类,它们是从ApplicationUser扩展而来的,它们具有共同的属性。我不知道如何从身份/页面/帐户/管理/索引来实施客户和员工。由于我只使用一个Model(InputModel)。我得到if语句在视图上显示客户表单或员工表单的信息,但是当Customer更新他们的数据时,会触发员工验证,反之亦然,因为我的属性全部在InputModel中。

型号

     public class InputModel
        {
        public string CustomerUserId { get; set; }
        public string EmployeeId { get; set; }

         //ApplicationUser
        [Required]
        public string FirstName { get; set; }
        [Required]
        public string LastName { get; set; }

        //CustomerUser
        [Required]
        public string InvoiceMethod { get; set; }

        //Employee
        [Required]
        public string SsnTaxId { get; set; }
        }

代码

  if (user.Employee != null && user.Employee.EmployeeId != null)
        {
            Input = new InputModel
            {
                EmployeeId = user.Employee.EmployeeId,
                Email = email,
             };
         }
          else if (user.Employee != null && user.Employee.EmployeeId != null)
        {
            Input = new InputModel
            {
                EmployeeId = user.Employee.EmployeeId,
                SSnTaxId= user.Employee.SsnTaxId,
             };
         }
          else if (user.Customer!= null && user.Customer.CustomerUserId!= null)
        {
            Input = new InputModel
            {
                CustomerUserId = user.Customer.CustomerUserId,
                InvoiceMethod= user.Customer.InvoiceMethod,
             };
         }

查看

          //ApplictionUser properties
      @if (Model.Input != null && Model.Input.CustomerUserId != null)
        {
           <input asp-for="Input.InvoiceMethod" class="form-control" type="text" />
           // display Customer Properties
         }
      @if (Model.Input != null && Model.Input.EmployeeId != null)
        {
          <input asp-for="Input.SsnTaxId" class="form-control" type="text" />
          //display employee properties
        }

0 个答案:

没有答案