英文:
Is this Domain Model correct?
问题
我开始为我的代码创建领域模型(我知道,领域模型应该首先创建),但我在弄清楚类之间的箭头应该是什么样子的问题上遇到了困难。从我所了解的信息中,我有了一点点想法,但我仍然感到相当困惑。
首先,这是我的领域模型的链接。
User
在创建新的 AppUser
类时用作模型,AppUser
类是 IdentityUser
的实现。
AppUser
仅在您想要进行登录
时使用。我真的不确定这两个类之间是否存在任何关系。下面您可以看到这两个类一起涉及的唯一部分。
public async Task<IActionResult> Login(Login login)
{
if (ModelState.IsValid)
{
AppUser appUser = await userManager.FindByEmailAsync(login.Email);
if (appUser != null)
{
await signInManager.SignOutAsync();
Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync(appUser, login.Password, false, false);
if (result.Succeeded)
return Redirect(login.ReturnUrl ?? "/");
}
ModelState.AddModelError(nameof(login.Email), "Login Failed: Invalid Email or password");
}
return View(login);
}
RoleEdit
和 RoleModification
用于将 dbo.AspNetUsers
中的条目分配给 dbo.AspNetRoles
中的角色。
public async Task<IActionResult> Update(string id)
{
IdentityRole role = await roleManager.FindByIdAsync(id);
List<AppUser> members = new List<AppUser>();
List<AppUser> nonMembers = new List<AppUser>();
foreach (AppUser user in userManager.Users)
{
var list = await userManager.IsInRoleAsync(user, role.Name) ? members : nonMembers;
list.Add(user);
}
return View(new RoleEdit
{
Role = role,
Members = members,
NonMembers = nonMembers
});
}
[HttpPost]
public async Task<IActionResult> Update(RoleModification model)
{
IdentityResult result;
if (ModelState.IsValid)
{
foreach (string userId in model.AddIds ?? new string[] { })
{
AppUser user = await userManager.FindByIdAsync(userId);
if (user != null)
{
result = await userManager.AddToRoleAsync(user, model.RoleName);
if (!result.Succeeded)
Errors(result);
}
}
foreach (string userId in model.DeleteIds ?? new string[] { })
{
AppUser user = await userManager.FindByIdAsync(userId);
if (user != null)
{
result = await userManager.RemoveFromRoleAsync(user, model.RoleName);
if (!result.Succeeded)
Errors(result);
}
}
}
if (ModelState.IsValid)
return RedirectToAction(nameof(Index));
else
return await Update(model.RoleId);
}
一个 Application
可以有多个 Releases
。如果删除一个应用程序,其发布也将被删除。此外,一个 Application
必须分配给一个单一的 Environment
(例如开发、测试等)。
一个 Release
可以有多个 Phases
。如果删除一个发布,其阶段也将被删除。与应用程序一样,Release
必须分配给一个单一的 Stage
。
一个 Phase
可以有多个 Tasks
。如果删除一个阶段,其任务不会被删除。
一个 Task
可以有多个 Dependencies
。
AppIdentityDbContext
是用于与数据库连接的类。
ErrorViewModel
是我仅使用一次的类,不是非常重要。是否应保留在领域模型中?
我想这就是大致情况。我给您提供的领域模型链接还没有完成,因为我不确定我是否在做正确的事情。您能提供的任何帮助、建议或提示对我来说都非常重要和受欢迎!
感谢阅读这篇冗长的帖子并帮助我。
英文:
NOTE: I am not sure if this is the correct place for this kind of questions. Although most questions ask about code, I also saw some questions regarding UML and diagrams. PLEASE, let me know if I've done an oopsie and I will immediately delete this post. Also, this post will contain quite a bit of code so I could explain better what is going on in the code.
I started working on a Domain Model for my code (I know, the Domain Model should have been first) but I have issues figuring out how the arrows between my classes should look like. From what I have read I got a slight idea but I am still rather confused.
Firstly this is a link to my domain model.
User
is used as a model when creating a new AppUser
, class which is an implementation of IdentityUser
.
AppUser
is used only when you want to Login
. I am really not sure if there is any relationship between these two classes. Below you can see the only part where these two classes are involved together.
public async Task<IActionResult> Login(Login login)
{
if (ModelState.IsValid)
{
AppUser appUser = await userManager.FindByEmailAsync(login.Email);
if (appUser != null)
{
await signInManager.SignOutAsync();
Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync(appUser, login.Password, false, false);
if (result.Succeeded)
return Redirect(login.ReturnUrl ?? "/");
}
ModelState.AddModelError(nameof(login.Email), "Login Failed: Invalid Email or password");
}
return View(login);
}
RoleEdit
and RoleModification
are used to assign an entry from dbo.AspNetUsers
to a role from dbo.AspNetRoles
.
public async Task<IActionResult> Update(string id)
{
IdentityRole role = await roleManager.FindByIdAsync(id);
List<AppUser> members = new List<AppUser>();
List<AppUser> nonMembers = new List<AppUser>();
foreach (AppUser user in userManager.Users)
{
var list = await userManager.IsInRoleAsync(user, role.Name) ? members : nonMembers;
list.Add(user);
}
return View(new RoleEdit
{
Role = role,
Members = members,
NonMembers = nonMembers
});
}
[HttpPost]
public async Task<IActionResult> Update(RoleModification model)
{
IdentityResult result;
if (ModelState.IsValid)
{
foreach (string userId in model.AddIds ?? new string[] { })
{
AppUser user = await userManager.FindByIdAsync(userId);
if (user != null)
{
result = await userManager.AddToRoleAsync(user, model.RoleName);
if (!result.Succeeded)
Errors(result);
}
}
foreach (string userId in model.DeleteIds ?? new string[] { })
{
AppUser user = await userManager.FindByIdAsync(userId);
if (user != null)
{
result = await userManager.RemoveFromRoleAsync(user, model.RoleName);
if (!result.Succeeded)
Errors(result);
}
}
}
if (ModelState.IsValid)
return RedirectToAction(nameof(Index));
else
return await Update(model.RoleId);
}
An Application
can have many Releases
. If an application is deleted, its releases will also be deleted. Also, an Application
must be issued a single Environment
(such as Development, Testing, etc.)
A Release
can have many Phases
. If a release is deleted, its phases will also be deleted. Same as the Applications, a Release
must be issued to a single Stage
.
A Phase
can have many Tasks
. If a phase is deleted, its tasks won't be deleted.
A Task
can have many Dependencies
.
AppIdentityDbContext
is a class used for the connection with the database.
ErrorViewModel
is a class that I used only once and is not really important. Should it be kept in the Domain Model?
I think that's pretty much it. The Domain Model that I gave you the link to is not yet done as I was unsure whether I am doing the right thing or not. Any help, advice, hints that you could give me are incredibly important and welcome!
Thanks to whoever read this lengthy post and could help me out.
答案1
得分: 0
登录与用户之间的关系...登录用于捕获登录表单中的信息,然后使用该信息在系统中查找用户并验证他们是否在系统中。它们在您的领域模型中没有关联,因为登录类在需要重定向时有一个返回URL,并且仅用于登录。它们具有不同的功能,在使用MVC模式编程的前提下,您正在分离您的关注点,这是一种良好的做法。
ViewModels是模型,因此您可以将领域数据暴露给视图,但它不是领域的一部分,因此ErrorViewModel不需要包含在您的图表中。
如果修改历史对您很重要,我建议为您认为重要的类添加ModifiedBy和ModifiedDate字段,以跟踪该信息。您还可以添加另一个字段“Deleted”,以便如果有人意外删除了不应删除的内容,您可以撤销该更改。您还可以向用户添加一个“LastLogin” dateTime字段,以跟踪用户的活动。
英文:
The relation between login and user...login is used to capture the information from the login form, you are then using that info to find the user in the system and verify that they are in the system. They are not linked in your domain model because the login class has a return url in case they need to be redirected and is used to just log someone in. They have separate function and under the premise of programming in an MVC pattern you are separating your concerns which is a good practice.
ViewModels are models so you can expose domain data to your view but is not part of the domain so ErrorViewModel does not need it be included in your diagram.
If modification history is important to you I would suggest a ModifiedBy and ModifiedDate field for the classes you feel it is important to track that info. You can also add another field 'Deleted' so if someone deletes something that wasnt supposed to be you can revert that change. You can also add a 'LastLogin" dateTime field to the user to track users activity.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论