fix edit profile

This commit is contained in:
Przemysław Stawujak 2019-01-13 21:06:54 +01:00
parent 5565bb7070
commit 912cbdbecf
2 changed files with 26 additions and 1 deletions

View File

@ -1,22 +1,27 @@
using Abp.Authorization; using System.Linq;
using Abp.Authorization;
using Abp.Domain.Repositories; using Abp.Domain.Repositories;
using Abp.Domain.Uow; using Abp.Domain.Uow;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks; using System.Threading.Tasks;
using SystemKonkursow.Authorization.Users; using SystemKonkursow.Authorization.Users;
using SystemKonkursow.UserProfile.Dto; using SystemKonkursow.UserProfile.Dto;
using Abp.UI;
namespace SystemKonkursow.UserProfile namespace SystemKonkursow.UserProfile
{ {
public class UserProfileAppService : SystemKonkursowAppServiceBase public class UserProfileAppService : SystemKonkursowAppServiceBase
{ {
private readonly UserManager _userManager; private readonly UserManager _userManager;
private readonly IRepository<User, long> _userRepository;
private readonly IRepository<Domain.Participant, int> _participantRepository; private readonly IRepository<Domain.Participant, int> _participantRepository;
public UserProfileAppService(UserManager userManager, public UserProfileAppService(UserManager userManager,
IRepository<User, long> userRepository,
IRepository<Domain.Participant, int> participantRepository) IRepository<Domain.Participant, int> participantRepository)
{ {
_userManager = userManager; _userManager = userManager;
_userRepository = userRepository;
_participantRepository = participantRepository; _participantRepository = participantRepository;
} }
@ -50,6 +55,25 @@ namespace SystemKonkursow.UserProfile
{ {
var user = await _userManager.GetUserByIdAsync(userProfile.Id); var user = await _userManager.GetUserByIdAsync(userProfile.Id);
var checkUserEmail = _userRepository.GetAll().Where(t => t.EmailAddress == userProfile.EmailAddress && t.Id != user.Id).FirstOrDefault();
var checkUserName = _userRepository.GetAll().Where(t => t.UserName == userProfile.UserName && t.Id != user.Id).FirstOrDefault();
if (null != checkUserEmail && null != checkUserName)
{
throw new UserFriendlyException(L("ProfileFailed"), string.Format("Użytkownik o adresie email: {0} i nazwie użytkownika: {1} już istnieje", userProfile.EmailAddress, userProfile.UserName));
}
if (null != checkUserEmail)
{
throw new UserFriendlyException(L("ProfileFailed"), string.Format("Użytkownik o adresie email: {0} już istnieje", userProfile.EmailAddress));
}
if (null != checkUserName)
{
throw new UserFriendlyException(L("ProfileFailed"), string.Format("Użytkownik o nazwie użytkownika: {0} już istnieje", userProfile.UserName));
}
ObjectMapper.Map(userProfile, user); ObjectMapper.Map(userProfile, user);
user.SetNormalizedNames(); user.SetNormalizedNames();

View File

@ -35,6 +35,7 @@
<text name="CanBeEmptyToLoginAsHost" value="Can be empty to login as host." /> <text name="CanBeEmptyToLoginAsHost" value="Can be empty to login as host." />
<text name="Register" value="Register" /> <text name="Register" value="Register" />
<text name="RegisterFailed" value="Błąd rejestracji!" /> <text name="RegisterFailed" value="Błąd rejestracji!" />
<text name="ProfileFailed" value="Błąd aktualizacji profilu!" />
<text name="OrLoginWith" value="Or login with" /> <text name="OrLoginWith" value="Or login with" />
<text name="WaitingForActivationMessage" value="Your account is waiting to be activated by system admin." /> <text name="WaitingForActivationMessage" value="Your account is waiting to be activated by system admin." />
<text name="TenantSelection" value="Tenant Selection" /> <text name="TenantSelection" value="Tenant Selection" />