MVC 5 带有两个注册表



是否可以甚至建议为同一应用程序创建2个注册表?我正在为这个项目使用 ASP.NET 身份 2.0。两种注册表具有相似的字段名称,但用途不同。一个用于教师培训,另一个用于捐赠。 创建两个单独的应用程序会更好吗?

示例 首次注册表格

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register1(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {
          var user = new ApplicationUser 
           { 
            UserName = model.Email, 
            Email = model.Email 
              };
        // Add the Address properties:
        user.Address = model.Address;
        user.City = model.City;
        user.State = model.State;
        user.PostalCode = model.PostalCode;
        // Additional fields specific to Registration Form1
        field1
        field2
        .....
        var result = await UserManager.CreateAsync(user, model.Password);
        if (result.Succeeded)
        {
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", 
                new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            await UserManager.SendEmailAsync(user.Id, 
                "Confirm your account", 
                "Please confirm your account by clicking this link: <a href="" 
                + callbackUrl + "">link</a>");
            ViewBag.Link = callbackUrl;
            return View("DisplayEmail");
        }
        AddErrors(result);
    }
    // If we got this far, something failed, redisplay form
    return View(model);
}

第二份注册表格

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register2(RegisterViewModel model)
     {
    if (ModelState.IsValid)
    {
          var user = new ApplicationUser 
           { 
            UserName = model.Email, 
            Email = model.Email 
              };
        // Add the Address properties:
        user.Address = model.Address;
        user.City = model.City;
        user.State = model.State;
        user.PostalCode = model.PostalCode;
        // Additional fields specific to Registration Form2
        field1
        field2
        SiteURL
        PaymentType
        var result = await UserManager.CreateAsync(user, model.Password);
        if (result.Succeeded)
        {
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", 
                new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            await UserManager.SendEmailAsync(user.Id, 
                "Confirm your account", 
                "Please confirm your account by clicking this link: <a href="" 
                + callbackUrl + "">link</a>");
            ViewBag.Link = callbackUrl;
            return View("DisplayEmail");
        }
        AddErrors(result);
    }
    // If we got this far, something failed, redisplay form
    return View(model);
}

是否可以甚至建议为同一应用程序创建 2 个注册表?

是的,这是可能的。

创建两个单独的应用程序会更好吗?

无需创建单独的应用程序 - 只需为业务和数据库提供底层结构和逻辑,以便相应地处理来自表单的输入。

最新更新