public async Task <List <User> > SyncGPSUsers(User currentUser) { List <User> gpsMembersUnderLead = await GetMembersUnderLead(currentUser.EmployeeId); List <User> ttMembersUnderLead = GetManageProfileVm(currentUser).AllUser; List <User> unsyncedMembers = new List <User>(); foreach (var gpsMember in gpsMembersUnderLead) { foreach (var ttMember in ttMembersUnderLead) { if (ttMember.UserName == gpsMember.UserName) { ttMember.EmployeeId = gpsMember.EmployeeId; if (!UserDataAccesor.UpdateUser(ttMember)) { unsyncedMembers.Add(ttMember); } } else { unsyncedMembers.Add(ttMember); } } } return(unsyncedMembers); }
/// <summary> /// Calls stored procedure which updates user. /// </summary> /// <param name="userData">User data object.</param> /// <param name="addedById">manager id</param> /// <returns>True if updated.</returns> public bool UpdateUser(User userData, int addedById) { userData.Password = Cryptography.Encrypt(userData.Password); var isUserUpdated = UserDataAccesor.UpdateUser(userData); var dbUser = GetUserByUserId(userData.UserId); var teamManagers = UnitOfWork.UserRepository .Find(u => u.TeamId == dbUser.TeamId && u.IsManager == true) .Select(lead => lead.UserId) .ToList(); try { if (isUserUpdated && dbUser.IsTrainee) { UnitOfWork.EmailAlertSubscriptionRepository .GetAllSubscribedMentors(userData.UserId, includeDeleted: true) .ForEach(s => { s.IsDeleted = !(userData.IsActive && teamManagers.Contains(s.SubscribedByUserId)); teamManagers.Remove(s.SubscribedByUserId); //Remove from managers if record exists. Also avoids duplicate notifications. UnitOfWork.EmailAlertSubscriptionRepository.AddOrUpdate(s); }); teamManagers.ForEach(manager => UnitOfWork.EmailAlertSubscriptionRepository .AddOrUpdate(new EmailAlertSubscription { SubscribedByUserId = manager, SubscribedForUserId = dbUser.UserId })); UnitOfWork.Commit(); if (dbUser.IsActive) { new NotificationBl().UserNotification(dbUser, addedById, isNewUser: false); } } } catch (Exception ex) { LogUtility.ErrorRoutine(ex); isUserUpdated = false; } return(isUserUpdated); }