Exemplo n.º 1
0
        public async Task AddUserAsyn(BranchUserModel branchUserModel, string agencyCode)
        {
            Check.ArgumentNotNull(nameof(branchUserModel), branchUserModel);
            var user = await _iDMAppService.FindUserProfileByUserNameAsync(branchUserModel.UserName);

            if (user != null)
            {
                _branchServiceDomain.AssignBranchUserExist(branchUserModel.BranchId, branchUserModel.RoleName, user);
            }
            List <IDMRolesModel> roles         = _iDMAppService.GetIDMRoles();
            IDMRolesModel        iDMRolesModel = roles.FirstOrDefault(r => r.Name == branchUserModel.RoleName);

            branchUserModel.RoleName   = iDMRolesModel.Name;
            branchUserModel.RoleArName = iDMRolesModel.NormalizedName;
            Enums.UserRole userType    = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName, true);
            UserProfile    userProfile = new UserProfile();

            if (user == null)
            {
                userProfile = await _iDMAppService.GetUserProfileByEmployeeId(branchUserModel.UserName, agencyCode, userType);

                Check.ArgumentNotNull(nameof(userProfile), userProfile);
                await _genericCommandRepository.CreateAsync(userProfile);

                branchUserModel.UserId = userProfile.Id;
            }
            else
            {
                var defaultSettingsForUserType = await _notificationAppService.GetDefaultSettingByUserType(userType);

                if (user.NotificationSetting.Count(x => x.UserRoleId == (int)userType) < defaultSettingsForUserType.Count)
                {
                    await _branchServiceDomain.CheckUserExist(user.Id, branchUserModel.BranchId, branchUserModel.RoleName);

                    user.AddNotificationSettings(defaultSettingsForUserType);
                    _genericCommandRepository.Update(user);
                }
                branchUserModel.UserId = user.Id;
            }
            var branchUser = new BranchUser(branchUserModel.BranchId, branchUserModel.UserId, (int)((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName)), branchUserModel.RelatedAgencyCode, branchUserModel.EstimatedValueFrom, branchUserModel.EstimatedValueTo);
            await _genericCommandRepository.CreateAsync(branchUser);

            await _genericCommandRepository.SaveAsync();

            if (user != null)
            {
                if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile))
                {
                    await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(userProfile.Email) || !string.IsNullOrEmpty(userProfile.Mobile))
                {
                    await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(userProfile.Id, userProfile.Email, userProfile.Mobile);
                }
            }
        }
Exemplo n.º 2
0
        public async Task AddUserAsyn(CommitteeUserModel committeeUserModel, string agencyCode)
        {
            Check.ArgumentNotNull(nameof(committeeUserModel), committeeUserModel);
            var user = await _iDMAppService.FindUserProfileByUserNameAsync(committeeUserModel.UserName);

            List <IDMRolesModel> roles         = _iDMAppService.GetIDMRoles();
            IDMRolesModel        iDMRolesModel = roles.FirstOrDefault(r => r.Name == committeeUserModel.RoleName);

            Enums.UserRole userType    = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), iDMRolesModel.Name, true);
            UserProfile    userProfile = new UserProfile();

            if (user == null)
            {
                userProfile = await _iDMAppService.GetUserProfileByEmployeeId(committeeUserModel.UserName, agencyCode, userType);

                Check.ArgumentNotNull(nameof(userProfile), userProfile);
                await _committeeDomainService.CheckUserExist(userProfile.Id, committeeUserModel.CommitteeId);

                await _genericCommandRepository.CreateAsync(userProfile);

                committeeUserModel.UserId = userProfile.Id;
            }
            else
            {
                var defaultSettingsForUserType = await _notificationAppService.GetDefaultSettingByUserType(userType);

                if (user.NotificationSetting.Count(x => x.UserRoleId == (int)userType) < defaultSettingsForUserType.Count)
                {
                    await _committeeDomainService.CheckUserExist(user.Id, committeeUserModel.CommitteeId);

                    user.AddNotificationSettings(defaultSettingsForUserType);
                    _genericCommandRepository.Update(user);
                }
                committeeUserModel.UserId = user.Id;
            }
            CommitteeUser committeeUser = new CommitteeUser(committeeUserModel.CommitteeId, committeeUserModel.UserId, (int)((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), iDMRolesModel.Name)), committeeUserModel.RelatedAgencyCode);
            await _genericCommandRepository.CreateAsync(committeeUser);

            await _genericCommandRepository.SaveAsync();

            if (user != null)
            {
                if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile))
                {
                    await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(userProfile.Email) || !string.IsNullOrEmpty(userProfile.Mobile))
                {
                    await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(userProfile.Id, userProfile.Email, userProfile.Mobile);
                }
            }
        }
Exemplo n.º 3
0
        public void AllowUserWithRole(params Enums.UserRole[] roles)
        {
            Enums.UserRole role = Enums.UserRole.None;

            Enum.TryParse(PrincipalHelper.GetUserPrincipal().Role, out role);

            bool allow = roles.Contains(role);

            if (!allow)
            {
                RedirectHome();
            }
        }
        public async Task AddUserToBranchAsyn(BranchUserAssignModel branchUserModel, string agencyCode)
        {
            Check.ArgumentNotNull(nameof(branchUserModel), branchUserModel);
            var user = await _iDMAppService.FindUserProfileByUserNameAsync(branchUserModel.NationalIdString);

            Enums.UserRole userRole = ((Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), branchUserModel.RoleName));
            if (user == null)
            {
                ManageUsersAssignationModel emp = await _iDMAppService.GetMonafastatEmployeeDetailById(agencyCode, branchUserModel.NationalIdString, "");

                UserProfile userProfile = new UserProfile(emp.userId, emp.nationalId, emp.fullName, emp.mobileNumber, emp.email, await _notificationAppService.GetDefaultSettingByUserType(userRole));
                Check.ArgumentNotNull(nameof(userProfile), userProfile);
                await _genericCommandRepository.CreateAsync(userProfile);

                branchUserModel.UserId = userProfile.Id;
            }
            else
            {
                if (!user.NotificationSetting.Any(x => x.UserRoleId == (int)userRole))
                {
                    await _branchServiceDomain.CheckUserExist(user.Id, branchUserModel.BranchId, branchUserModel.RoleName);

                    user.AddNotificationSettings(await _notificationAppService.GetDefaultSettingByUserType(userRole));
                    _genericCommandRepository.Update(user);
                }
                branchUserModel.UserId = user.Id;
            }
            var branchUser = new BranchUser(branchUserModel.BranchId, branchUserModel.UserId.Value, (int)userRole, branchUserModel.RelatedAgencyCode, branchUserModel.EstimatedValueFrom, branchUserModel.EstimatedValueTo);
            await _genericCommandRepository.CreateAsync(branchUser);

            await _genericCommandRepository.SaveAsync();

            if (user == null)
            {
                if (!string.IsNullOrEmpty(branchUser.UserProfile.Email) || !string.IsNullOrEmpty(branchUser.UserProfile.Mobile))
                {
                    await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(branchUser.UserProfile.Id, branchUser.UserProfile.Email, branchUser.UserProfile.Mobile);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(user.Email) || !string.IsNullOrEmpty(user.Mobile))
                {
                    await _notificationAppService.SendNotificationByEmailAndSmsForRolesChanged(user.Id, user.Email, user.Mobile);
                }
            }
        }
Exemplo n.º 5
0
        public void Invoke_HigherRole_NotSavedInDatabase(UserRole oldRole, Enums.UserRole newRole)
        {
            // Prepare
            var dataUserApp = new UserApps
            {
                User = new DataAccess.Models.User {
                    Id = 1
                },
                App = new DataAccess.Models.App {
                    Id = 1
                },
                Role = oldRole
            };
            var dataUser = new DataAccess.Models.User
            {
                IsSuperAdmin = false
            };
            var getAllResults = new List <UserApps> {
                dataUserApp
            };
            var mockedUserAppsRepository = new Mock <IUserAppRepository>();
            var mockedUserRepository     = new Mock <IUserRepository>();
            var mockedAddNewUserApp      = new Mock <IAddNewUserApp>();

            mockedUserRepository.Setup(r => r.GetById(It.IsAny <int>()))
            .Returns(dataUser);
            mockedUserAppsRepository.Setup(r => r.FindBy(It.IsAny <Expression <Func <UserApps, bool> > >()))
            .Returns(getAllResults.AsQueryable());

            var action = new RevokeRole(mockedUserAppsRepository.Object,
                                        mockedUserRepository.Object,
                                        mockedAddNewUserApp.Object);

            // Action
            var actionResult = action.Invoke(1, 1, newRole);

            // Check
            Assert.False(actionResult);
            mockedUserAppsRepository.Verify(r => r.Edit(It.IsAny <UserApps>()), Times.Never);
            mockedUserAppsRepository.Verify(r => r.Save(), Times.Never);
            mockedUserRepository.Verify(r => r.Edit(It.IsAny <DataAccess.Models.User>()), Times.Never);
            mockedUserRepository.Verify(r => r.Save(), Times.Never);
            mockedAddNewUserApp.Verify(r => r.Invoke(It.IsAny <UserAppModel>()), Times.Never);
        }
Exemplo n.º 6
0
        public async Task SendToLevelTwoFromUnitSecretaryLevelOneAsync(string tenderIdString, string userName, string notes)
        {
            var    tenderId = Util.Decrypt(tenderIdString);
            Tender tender   = await _tenderQueries.FindTenderWithUnitHistoryById(tenderId);

            _tenderDomainService.IsValidToSendToLevelTwoFromUnitSecretaryLevelOne(tender, userName);
            var user = await _iDMAppService.FindUserProfileByUserNameAsync(userName);

            if (user == null)
            {
                Enums.UserRole userType = (Enums.UserRole)Enum.Parse(typeof(Enums.UserRole), RoleNames.UnitSpecialistLevel2, true);
                user = await _iDMAppService.GetUserProfileByEmployeeId(userName, null, userType);

                Check.ArgumentNotNull(nameof(user), user);
                await _genericCommandRepository.CreateAsync(user);
            }
            TenderUnitAssign tenderUnitAssign = new TenderUnitAssign(user.Id, tenderId, true, (int)UnitSpecialistLevel.UnitSpecialistLevelTwo);

            tender.SetUnitStatus(Enums.TenderUnitStatus.TenderTransferdToLevelTwo);
            TenderUnitStatusesHistory tenderUnitStatusesHistory = new TenderUnitStatusesHistory(comment: notes, tenderUnitStatusId: (int)Enums.TenderUnitStatus.TenderTransferdToLevelTwo, estimatedValue: tender.EstimatedValue);

            tender.TenderUnitStatusesHistories.Add(tenderUnitStatusesHistory);
            #region [Send Notification]
            NotificationArguments NotificationArguments = new NotificationArguments
            {
                BodyEmailArgs    = new object[] { tender.ReferenceNumber },
                SubjectEmailArgs = new object[] { },
                PanelArgs        = new object[] { tender.ReferenceNumber },
                SMSArgs          = new object[] { tender.ReferenceNumber }
            };
            MainNotificationTemplateModel mainNotificationTemplateModel = new MainNotificationTemplateModel(NotificationArguments,
                                                                                                            $"Tender/TenderDetailsForUnitSecretary?tenderIdString={Util.Encrypt(tender.TenderId)}",
                                                                                                            NotificationEntityType.Tender,
                                                                                                            tender.TenderId.ToString(),
                                                                                                            tender.BranchId);
            await _notificationAppService.SendNotificationForCommitteeUsers(NotificationOperations.UnitSecrtaryLevel2.OperationsOnTheTender.reviewTender, null, mainNotificationTemplateModel);

            #endregion
            await _tenderCommands.UpdateAsync(tender);

            await _genericCommandRepository.CreateAsync(tenderUnitAssign);

            await _genericCommandRepository.SaveAsync();
        }
Exemplo n.º 7
0
 public bool IsInRole(Enums.UserRole role)
 {
     return(Roles.Contains(role));
 }
Exemplo n.º 8
0
 public WorkingUser()
 {
     Roles = new Enums.UserRole[] { };
 }
Exemplo n.º 9
0
 public async Task <List <UserNotificationSetting> > GetDefaultSettingByUserType(Enums.UserRole userType)
 {
     return(await _iNotificationQuerie.GetDefaultSettingByUserType(userType));
 }
Exemplo n.º 10
0
        public async Task SaveNotificationSetting(List <UserNotificatioSettingModel> userNotificatioSettings, int userId, Enums.UserRole userRole, string CR = "")
        {
            if (userRole == Enums.UserRole.NewMonafasat_Supplier)
            {
                var userProfile = await _iNotificationQuerie.GetSupplierUser(CR);

                foreach (var setting in userNotificatioSettings)
                {
                    userProfile.UpdateNotificationSetting(Util.Decrypt(setting.Id), setting.EmailEnabled, setting.SMSEnabled);
                }
                await _notifayCommands.UpdateSupplierAsync(userProfile);
            }
            else
            {
                var userProfile = await _iNotificationQuerie.GetUser(userId);

                foreach (var setting in userNotificatioSettings)
                {
                    userProfile.UpdateNotificationSetting(Util.Decrypt(setting.Id), setting.EmailEnabled, setting.SMSEnabled);
                }
                await _notifayCommands.UpdateAsync(userProfile);
            }
        }
Exemplo n.º 11
0
 public async Task <List <UserCategoryNotificatioSettingModel> > GetUserNotificationSetting(int userId, string cr, Enums.UserRole userType)
 {
     return(await _iNotificationQuerie.FindUserNotificationSetting(userId, cr, userType));
 }