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); } } }
public async Task <Committee> CreateAsync(Committee committee) { Check.ArgumentNotNull(nameof(committee), committee); await _committeeDomainService.CheckNameExistbyType(committee.CommitteeName, committee.AgencyCode, committee.CommitteeTypeId); var res = await _genericCommandRepository.CreateAsync <Committee>(committee); await _genericCommandRepository.SaveAsync(); return(res); }
public async Task <PrePlanningModel> CreateAsync(PrePlanningModel model) { Check.ArgumentNotNull(nameof(model), model); PrePlanning planning; await _prePlanningDomainService.CheckNameExist(model.ProjectName, model.BranchId, model.YearQuarterId, model.AgencyCode, model.PrePlanningId); if (model.PrePlanningId == 0) { planning = new PrePlanning(model.PrePlanningId, model.AgencyCode, model.BranchId, model.ProjectName, model.ProjectNature, model.ProjectTypeId, model.ProjectDescription, model.InsideKSA, (int)Enums.PrePlanningStatus.UnderUpdate, model.Duration, model.DurationInDays, model.DurationInMonths, model.DurationInYears, model.YearQuarterId); planning.IsDurationValid(); planning.AddtAreasCountriesTypes(model.PrePlanningAreaIDs, model.InsideKSA, model.PrePlanningCountriesIDs, model.ProjectTypesIDs); planning = await _genericCommandRepository.CreateAsync <PrePlanning>(planning); } else { planning = await _prePlanningQueries.FindByIdForEdit(model.PrePlanningId); if (planning.StatusId == (int)Enums.PrePlanningStatus.Pending || planning.StatusId == (int)Enums.PrePlanningStatus.Rejected) { throw new UnHandledAccessException(); } planning.Update(model.AgencyCode, model.ProjectName, model.ProjectNature, model.ProjectDescription, model.InsideKSA, (int)Enums.PrePlanningStatus.UnderUpdate, model.Duration, model.DurationInDays, model.DurationInMonths, model.DurationInYears, model.YearQuarterId); planning.IsDurationValid(); planning = planning.UpdatetAreasCountriesTypes(model.PrePlanningAreaIDs, model.InsideKSA, model.PrePlanningCountriesIDs, model.ProjectTypesIDs); _genericCommandRepository.Update <PrePlanning>(planning); } await _genericCommandRepository.SaveAsync(); model.PrePlanningId = planning.PrePlanningId; return(model); }
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); } } }
public async Task CreateVerificationCode(int codeTypeId, string userMobile, string userEmail, int userID, int typeId) { var verificationCode = Util.RandomString(5); VerificationCode vCode = new VerificationCode(verificationCode, userID, typeId, codeTypeId); NotificationArguments NotificationArgument = new NotificationArguments { BodyEmailArgs = new object[] { "", verificationCode }, SubjectEmailArgs = new object[] { }, PanelArgs = new object[] { }, SMSArgs = new object[] { verificationCode } }; MainNotificationTemplateModel verficationCodeModel = new MainNotificationTemplateModel(NotificationArgument); int operationCode = 0; if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.Auditer) { operationCode = NotificationOperations.Auditor.OperationsNeedApprove.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.DataEntry) { operationCode = NotificationOperations.DataEntry.OperationsNeedApprove.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.OffersOppeningManager) { operationCode = NotificationOperations.OffersOppeningManager.TransactionsNeedApproval.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.OffersCheckManager) { operationCode = NotificationOperations.OffersCheckManager.OperationsNeedToBeAccredited.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.MonafasatBlackListCommittee) { operationCode = NotificationOperations.BlockManager.OperationsToBeApproved.ApproveVerificationBlockManager; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.OffersPurchaseManager) { operationCode = NotificationOperations.DirectPurchaseManager.OperationsOnTheTender.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.PrePlanningAuditor) { operationCode = NotificationOperations.PrePlaningAuditor.OperationsOnPrePlaning.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.PreQualificationCommitteeManager) { operationCode = NotificationOperations.PreQualificationManager.OperationsOnPreQualification.QualificationVerficationCodeApproval; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.OffersOpeningAndCheckManager) { operationCode = NotificationOperations.VROCheckManager.OperationsOnTheTender.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.EtimadOfficer) { operationCode = NotificationOperations.EtimadOfficer.OperationsNeedApprove.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.ApproveTenderAward) { operationCode = NotificationOperations.ApproveTenderAwarding.OperationsOnTheTender.approvaloperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.OffersCheckSecretary) { operationCode = NotificationOperations.OffersCheckSecretary.OperationsOnTheTender.BiddingVerficationCode; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.MandatoryListApprover) { operationCode = NotificationOperations.MandatoryListApprover.MandatoryListProducts.ApprovalOperation; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.UnitManagerUser) { operationCode = NotificationOperations.UnitManager.OperationsOnTheTender.SendVerificationCode; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.UnitSpecialistLevel1) { operationCode = NotificationOperations.UnitSecrtaryLevel1.OperationsOnTheTender.SendVerificationCode; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.UnitSpecialistLevel2) { operationCode = NotificationOperations.UnitSecrtaryLevel2.OperationsOnTheTender.SendVerificationCode; } else if (_httpContextAccessor.HttpContext.User.UserRole() == RoleNames.OffersPurchaseSecretary) { operationCode = NotificationOperations.DirectPurchaseSecretary.OperationsOnTheTender.SendVerificationCode; } await _notificationAppService.SendNotificationDirectByUserId(operationCode, userID, verficationCodeModel); await _genericCommandRepository.CreateAsync(vCode); await _genericCommandRepository.SaveAsync(); }
public async Task <SupplierBlock> AddBlockAsyn(SupplierBlock block) { var supplier = await _supplierQueries.FindSupplierByCRNumber(block.CommercialRegistrationNo); if (supplier == null) { var supplierobj = new Supplier(block.CommercialRegistrationNo, block.CommercialSupplierName, await _notificationAppService.GetDefaultSettingByCr()); await _genericrepository.CreateAsync(supplierobj); } else { List <UserNotificationSetting> defaultNotificationSettings = await _notificationAppService.GetDefaultSettingByCr(); if (supplier.NotificationSetting.Count < defaultNotificationSettings.Count) { supplier.AddNotificationSettings(defaultNotificationSettings); _genericrepository.Update(supplier); } } if (block.BlockTypeId == 1) { if (block.BlockStartDate != null && block.BlockStartDate != DateTime.MinValue && block.BlockStartDate < DateTime.Now) { throw new BusinessRuleException(Resources.BlockResources.ErrorMessages.PermanentDateValidate); } } else { if (block.BlockEndDate != null && block.BlockEndDate != DateTime.MinValue && block.BlockEndDate < DateTime.Now) { throw new BusinessRuleException(Resources.BlockResources.ErrorMessages.DateValidation); } } QueryResult <SupplierBlockModel> supplierBlock = await _blockQueries.FindBlockedUser(new BlockSearchCriteria { AgencyCode = block.AgencyCode, CommercialRegistrationNo = block.CommercialRegistrationNo, BlockStatusId = (int)IsActive.Active }); if (supplierBlock != null && supplierBlock.TotalCount > 0) { if (supplierBlock.Items.FirstOrDefault().BlockStatusId == (int)Enums.BlockStatus.NewAdmin || supplierBlock.Items.FirstOrDefault().BlockStatusId == (int)Enums.BlockStatus.NewSecretary || supplierBlock.Items.FirstOrDefault().BlockStatusId == (int)Enums.BlockStatus.ApprovedSecertary) { throw new BusinessRuleException(Resources.BlockResources.Messages.BlockPendingRequest); } else { throw new BusinessRuleException(Resources.BlockResources.ErrorMessages.AlreadyBlocked); } } Check.ArgumentNotNull(nameof(SupplierBlock), block); var res = await _genericrepository.CreateAsync(block); await _genericrepository.SaveAsync(); NotificationArguments NotificationArguments = new NotificationArguments { BodyEmailArgs = new object[] { block.CommercialRegistrationNo, block.CommercialSupplierName }, SubjectEmailArgs = new object[] { }, PanelArgs = new object[] { block.CommercialRegistrationNo, block.CommercialSupplierName }, SMSArgs = new object[] { block.CommercialRegistrationNo, block.CommercialSupplierName } }; NotificationArguments NotificationArgumentsForSupplier = new NotificationArguments { BodyEmailArgs = new object[] { block.CommercialSupplierName }, SubjectEmailArgs = new object[] { }, PanelArgs = new object[] { block.CommercialSupplierName }, SMSArgs = new object[] { block.CommercialSupplierName } }; MainNotificationTemplateModel mainNotificationTemplateModelForSecretary = new MainNotificationTemplateModel(NotificationArguments, $"Block/SecretaryBlockDetails?Id={Util.Encrypt(block.SupplierBlockId)}", NotificationEntityType.Block, block.SupplierBlockId.ToString(), 0); MainNotificationTemplateModel mainNotificationTemplateModelForSupplier = new MainNotificationTemplateModel(NotificationArgumentsForSupplier, $"Block/BlockDetailsAsync?Id={Util.Encrypt(block.SupplierBlockId)}", NotificationEntityType.Block, block.SupplierBlockId.ToString(), 0); MainNotificationTemplateModel mainNotificationTemplateModelForAccountMangerSpecialist = new MainNotificationTemplateModel(NotificationArguments, $"Block/BlockDetailsAsync?Id={Util.Encrypt(block.SupplierBlockId)}", NotificationEntityType.Block, block.SupplierBlockId.ToString(), 0); await _notificationAppService.SendNotificationForSuppliers(NotificationOperations.BlockManager.OperationsToBeApproved.sendApprovedManagerApprovedBlocked, new List <string> { block.CommercialRegistrationNo }, mainNotificationTemplateModelForSupplier); await _notificationAppService.SendNotificationForUsersByRoleName(NotificationOperations.BlockSecrtary.OperationsToBeApproved.ApproveBlockFromManagerToSecretary, RoleNames.MonafasatBlockListSecritary, mainNotificationTemplateModelForSecretary); await _notificationAppService.SendNotificationForUsersByRoleName(NotificationOperations.BlockManager.OperationsToBeApproved.AppoveBlockFromMangerToAccountMangerSpecialist, RoleNames.AccountsManagementSpecialist, mainNotificationTemplateModelForAccountMangerSpecialist); return(res); }