Hi, I read in the documentation that whenever a code is withing UOW, there is no need to explicitly calling update method on the repository, as this is handled automatically by the framework.
What are the cases that I need to actually call update methods?
Thanks
7 Answer(s)
-
0
Hi,
Actually there is no need to call update method in a unit of work.
-
0
Thanks. But existing code of ABP Framework does it in more than places, so I got confused.
-
0
Hi,
Can you share an example, I might be wrong about it.
Thanks.
-
0
Here you go:
[AbpAuthorize(AppPermissions.Pages_Administration_Users_Edit)] protected virtual async Task UpdateUserAsync(CreateOrUpdateUserInput input) { Debug.Assert(input.User.Id != null, "input.User.Id should be set."); var user = await UserManager.FindByIdAsync(input.User.Id.Value); //Update user properties input.User.MapTo(user); //Passwords is not mapped (see mapping configuration) if (input.SetRandomPassword) { input.User.Password = User.CreateRandomPassword(); } if (!input.User.Password.IsNullOrEmpty()) { CheckErrors(await UserManager.ChangePasswordAsync(user, input.User.Password)); } CheckErrors(await UserManager.UpdateAsync(user)); //Update roles CheckErrors(await UserManager.SetRoles(user, input.AssignedRoleNames)); if (input.SendActivationEmail) { user.SetNewEmailConfirmationCode(); await _userEmailer.SendEmailActivationLinkAsync(user, input.User.Password); } }
-
0
Hi,
In this case, it is used to check if there are errors on updating user. And the update method belongs to UserManager class which is not a repository.
Thanks.
-
0
I understand, so if there is no need to check for errors, you simply don't cal l any update method?
Thanks
-
0
Yes, you are right.