Exemplo n.º 1
0
        private void AddOrUpdateEmployee(EKontoUser eKontoUser, EKadryEmployee eKadryEmployee, Institute institute)
        {
            Promoter promoter = _context.Promoters.Where(p => p.Id == eKadryEmployee.id).FirstOrDefault();

            if (promoter == null)
            {
                promoter = new Promoter
                {
                    Id          = eKadryEmployee.id,
                    InstituteId = institute.Id,
                    ExpectedNumberOfBachelorProposals = 0,
                    ExpectedNumberOfMasterProposals   = 0,
                    UserId = eKontoUser.id
                };
                _mapper.Map(eKontoUser, promoter);
                _mapper.Map(eKadryEmployee, promoter);
                _context.Promoters.Add(promoter);
            }
            else
            {
                _mapper.Map(eKontoUser, promoter);
                _mapper.Map(eKadryEmployee, promoter);
                promoter.InstituteId = institute.Id;
                _context.Promoters.Update(promoter);
            }
            _context.SaveChanges();
        }
Exemplo n.º 2
0
        private void AddOrUpdatePromoterUser(EKontoUser eKontoUser)
        {
            var role         = _context.Roles.FirstOrDefault(r => r.Name == "Promoter");
            var existingUser = _context.Users.FirstOrDefault(u => u.Id == eKontoUser.id);

            if (existingUser == null)
            {
                var user = new User();
                user               = _mapper.Map(eKontoUser, user);
                user.Id            = eKontoUser.id;
                user.SecurityStamp = "";
                _context.Users.Add(user);
                _context.UserRoles.Add(new IntUserRole {
                    UserId = eKontoUser.id,
                    RoleId = role.Id
                });
            }
            else
            {
                var user = _mapper.Map(eKontoUser, existingUser);
                _context.Users.Update(user);
                var userRoles = _context.UserRoles.Where(r => r.UserId == eKontoUser.id);
                _context.UserRoles.RemoveRange(userRoles);
                _context.SaveChanges();
                _context.UserRoles.Add(new IntUserRole {
                    UserId = eKontoUser.id,
                    RoleId = role.Id
                });
            }
            _context.SaveChanges();
        }
Exemplo n.º 3
0
        private string GetNormalizedEmailOf(EKontoUser eKontoUser)
        {
            var email = eKontoUser.GetLogin();

            return(new UpperInvariantLookupNormalizer()
                   .Normalize(email)
                   .ToLowerInvariant());
        }
Exemplo n.º 4
0
 private bool IsPromoter(EKontoUser user)
 {
     if (user.loginDomain != "put.poznan.pl")
     {
         return(false);
     }
     return(_context.Promoters.Any(p => p.UserId == user.id));
 }
Exemplo n.º 5
0
        private async Task <User> UpdateUser(User existingUser, EKontoUser eKontoUser, IEnumerable <string> roleNames)
        {
            var user = _mapper.Map(eKontoUser, existingUser);

            var currentRoles = await _userManager.GetRolesAsync(user);

            await _userManager.RemoveFromRolesAsync(user, currentRoles);

            await _userManager.AddToRolesAsync(user, roleNames);

            await _context.SaveChangesAsync();

            await SetSecurityStampAsync(user, roleNames);

            return(user);
        }
Exemplo n.º 6
0
        private async Task <User> CreateUserFrom(EKontoUser eKontoUser, IEnumerable <string> roleNames)
        {
            var user = new User();

            user               = _mapper.Map(eKontoUser, user);
            user.Id            = eKontoUser.id;
            user.SecurityStamp = "";

            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            await _userManager.AddToRolesAsync(user, roleNames);

            await SetSecurityStampAsync(user, roleNames);

            return(user);
        }