Пример #1
0
        public async Task <SupplierBlock> AddAdminBlock(SupplierBlockModel blockModel)
        {
            SupplierBlock block    = new SupplierBlock(blockModel.CommercialRegistrationNo, blockModel.CommercialSupplierName, blockModel.ResolutionNumber, blockModel.BlockStatusId, 2, blockModel.AgencyCode, blockModel.BlockStartDate, blockModel.BlockEndDate, blockModel.Punishment, blockModel.BlockDetails, blockModel.AdminFileName, blockModel.AdminFileNetReferenceId, blockModel.SecretaryFileName, blockModel.SecretaryFileNetReferenceId, blockModel.AdminBlockReason, blockModel.SecretaryBlockReason, blockModel.SupplierTypeId, blockModel.OrganizationTypeId, blockModel.CommercialRegistrationNo, blockModel.CommercialRegistrationNo, false);
            string        crNumber = blockModel.CommercialRegistrationNo;
            var           supplier = await _supplierQueries.FindSupplierByCRNumber(crNumber);

            if (supplier == null)
            {
                Supplier supplierobj = new Supplier(crNumber, blockModel.CommercialSupplierName, await _notificationAppService.GetDefaultSettingByCr());
                await _genericrepository.CreateAsync <Supplier>(supplierobj);
            }
            else
            {
                List <UserNotificationSetting> defaultNotificationSettings = await _notificationAppService.GetDefaultSettingByCr();

                supplier.AddNotificationSettings(defaultNotificationSettings);
                _genericrepository.Update(supplier);
            }

            QueryResult <SupplierBlockModel> supplierBlock = await _blockQueries.FindBlockedUser(new BlockSearchCriteria { AgencyCode = block.AgencyCode, CommercialRegistrationNo = block.CommercialRegistrationNo, EnabledSearchByDate = blockModel.EnabledSearchByDate });

            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[] { blockModel.CommercialSupplierName },
                SubjectEmailArgs = new object[] { },
                PanelArgs        = new object[] { blockModel.CommercialSupplierName },
                SMSArgs          = new object[] { blockModel.CommercialSupplierName }
            };

            if (blockModel.IsSecretaryNotify)
            {
                MainNotificationTemplateModel mainNotificationTemplateModelForManger = new MainNotificationTemplateModel(NotificationArguments,
                                                                                                                         $"Block/ManagerBlockDetails?Id={Util.Encrypt(block.SupplierBlockId)}", NotificationEntityType.Block, blockModel.SupplierBlockId.ToString(), 0);
                await _notificationAppService.SendNotificationForUsersByRoleName(NotificationOperations.BlockManager.OperationsToBeApproved.ApproveBlockManager, RoleNames.MonafasatBlackListCommittee, mainNotificationTemplateModelForManger);
            }
            else
            {
                MainNotificationTemplateModel mainNotificationTemplateModelForSecretary = new MainNotificationTemplateModel(NotificationArguments,
                                                                                                                            $"Block/SecretaryBlockDetails?Id={Util.Encrypt(block.SupplierBlockId)}", NotificationEntityType.Block, block.SupplierBlockId.ToString(), 0);
                await _notificationAppService.SendNotificationForUsersByRoleName(NotificationOperations.BlockMonafasatAdmin.OperationsRequest.SendRequestBlockFromMonafasatAdminToBlockSecrtary, RoleNames.MonafasatBlockListSecritary, mainNotificationTemplateModelForSecretary);
            }

            return(res);
        }
Пример #2
0
        public async Task UpdateBlock_Returns_Throws_AlreadyBlocked()
        {
            var _supplierBlockModel = new SupplierBlockModel()
            {
                SupplierBlockId          = 64,
                CommercialRegistrationNo = "1010274503",
                CommercialSupplierName   = "الشركة السعودية لتبادل المعلومات الكترونيا تبادل",
                AdminFileName            = "CR  العملات الأجنبية V2.2 (1).pdf",
                AdminFileNetReferenceId  = "idd_8A7F7375-6A6F-CAC5-8671-6D78C5300000",
                BlockDetails             = "منع دائم - قديم - تاريخ المنع - غدا",
                BlockTypeId      = 1,
                SupplierTypeId   = 1,
                IsOldSystem      = false,
                ResolutionNumber = "99",
                BlockStartDate   = DateTime.Now.AddDays(2),
                Punishment       = "نص العقوبة",
                AgencyCode       = "019001000000",
                BlockStatusId    = 5,
                IsTotallyBlocked = false
            };

            var result = await _blockController.UpdateBlock(_supplierBlockModel);

            var okResult = result as OkObjectResult;

            Assert.NotNull(result);
            Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode);
        }
Пример #3
0
        public async Task ShouldAddAdminBlockWithUserNotificationSettings()
        {
            _moqBlockQueries.Setup(q => q.FindBlockedUser(It.IsAny <BlockSearchCriteria>())).Returns(() =>
            {
                return(Task.FromResult(new QueryResult <SupplierBlockModel>(new List <SupplierBlockModel> {
                }, 0, 1, 10)));
            });

            _moqSupplierQueries.Setup(q => q.FindSupplierByCRNumber(It.IsAny <string>())).Returns(() =>
            {
                return(Task.FromResult <Supplier>(new IDMDefaults().GetSupplierData()));
            });

            _moqnotificationappService.Setup(m => m.GetDefaultSettingByCr())
            .Returns(() =>
            {
                return(Task.FromResult <List <UserNotificationSetting> >(new BranchUserDefaults().GetUserNotificationSettings()));
            });

            var _blockObj = new SupplierBlockModel()
            {
                CommercialRegistrationNo = "789645", CommercialSupplierName = "789645312", AdminBlockReason = "8746512"
            };

            _moqCommandRepository.Setup(m => m.CreateAsync(It.IsAny <SupplierBlock>())).Returns <SupplierBlock>(r =>
            {
                return(Task.FromResult(new SupplierBlockDefaults().ReturnSupplierBlockDefaults()));
            });

            var result = await _sut.AddAdminBlock(_blockObj);

            Assert.NotNull(result);
            Assert.IsType <SupplierBlock>(result);
            GeneralFields.supplierBlockId = result.SupplierBlockId;
        }
Пример #4
0
        public async Task GetBlockByIdForSupplier_Returns_Data()
        {
            var _supplierBlockId = 64;
            var _expectedResult  = new SupplierBlockModel()
            {
                AgencyCode = "VRO000007",
                CommercialRegistrationNo = "1010254223",
                ResolutionNumber         = "99",
                SupplierBlockId          = 64,
                SupplierBlockIdString    = "LREqj6Fy4ZfJ4UFZE8jsVg==",
                SupplierTypeId           = 1
            };

            var result = await _blockController.GetBlockByIdForSupplier(_supplierBlockId);

            Assert.NotNull(result);
            Assert.IsType <SupplierBlockModel>(result);
            Assert.Equal(_expectedResult.AgencyCode, result.AgencyCode);
            Assert.Equal(_expectedResult.CommercialRegistrationNo, result.CommercialRegistrationNo);
            Assert.Equal(_expectedResult.ResolutionNumber, result.ResolutionNumber);
            Assert.Equal(_expectedResult.SupplierBlockId, result.SupplierBlockId);
            Assert.Equal(_expectedResult.SupplierBlockIdString, result.SupplierBlockIdString);
            Assert.Equal(_expectedResult.SupplierTypeId, result.SupplierTypeId);
            Assert.False(result.IsOldSystem);
        }
Пример #5
0
        public async Task ShouldAddSecretaryBlock()
        {
            _moqBlockQueries.Setup(x => x.FindBlockById(It.IsAny <int>()))
            .Returns(() =>
            {
                SupplierBlockModel obj = new SupplierBlockModel();
                return(Task.FromResult <SupplierBlockModel>(obj));
            });
            _moqBlockCommands.Setup(x => x.UpdateAsync(It.IsAny <SupplierBlock>()))
            .Returns((SupplierBlock obj) =>
            {
                return(Task.FromResult <SupplierBlock>(obj));
            });
            _moqBlockQueries.Setup(x => x.FindBlockByIdAsync(It.IsAny <int>()))
            .Returns(() =>
            {
                return(Task.FromResult <SupplierBlock>(new SupplierBlock()));
            });
            //=== arrange=========
            var _blockObj = new SupplierBlockModel()
            {
                SupplierBlockId = GeneralFields.supplierBlockId
            };

            //============Return Result===========
            var result = await _sut.AddSecretaryBlock(_blockObj);

            //====== Assert=====
            Assert.NotNull(result);
            Assert.IsType <SupplierBlock>(result);
        }
Пример #6
0
        public async Task <SupplierBlock> UpdateBlockAsync(SupplierBlockModel blockModel)
        {
            Check.ArgumentNotNull(nameof(SupplierBlockModel), blockModel);
            var block = await FindBlockByIdAsync(blockModel.SupplierBlockId);

            Check.ArgumentNotNull(nameof(SupplierBlock), block);
            block.UpdateBlock(blockModel.CommercialRegistrationNo, blockModel.CommercialSupplierName, blockModel.ResolutionNumber, blockModel.BlockStatusId, blockModel.AgencyCode, blockModel.BlockStartDate, blockModel.BlockEndDate, blockModel.Punishment, blockModel.AdminFileName, blockModel.AdminFileNetReferenceId, blockModel.SecretaryFileName, blockModel.SecretaryFileNetReferenceId, blockModel.AdminBlockReason, blockModel.SecretaryBlockReason);
            return(await _blockCommands.UpdateAsync(block));
        }
Пример #7
0
        public async Task <IActionResult> AddAdminBlock([FromBody] SupplierBlockModel blockModel)
        {
            blockModel.AgencyCode          = User.UserAgency();
            blockModel.BlockStatusId       = (int)Enums.BlockStatus.NewAdmin;
            blockModel.EnabledSearchByDate = false;
            await _blockService.AddAdminBlock(blockModel);

            return(Ok());
        }
Пример #8
0
        public async Task <IActionResult> AddSecretaryBlock([FromBody] SupplierBlockModel blockModel)
        {
            if (string.IsNullOrEmpty(blockModel.AgencyCode))
            {
                blockModel.AgencyCode = User.UserAgency();
            }
            await _blockService.AddSecretaryBlock(blockModel);

            return(Ok());
        }
Пример #9
0
        public async Task SecretaryRejectionReason_Success()
        {
            var _supplierBlockModel = new SupplierBlockModel()
            {
                SupplierBlockId          = 83,
                SecretaryRejectionReason = "Secretary Rejection Reason"
            };

            await _blockController.SecretaryRejectionReason(_supplierBlockModel);
        }
Пример #10
0
        public async Task ManagerRejectionReason_Success()
        {
            var _supplierBlockModel = new SupplierBlockModel()
            {
                SupplierBlockId        = 80,
                ManagerRejectionReason = "Manager Rejection Reason"
            };

            await _blockController.ManagerRejectionReason(_supplierBlockModel);
        }
Пример #11
0
        public async Task <IActionResult> AddBlock([FromBody] SupplierBlockModel blockModel)
        {
            if (User.UserRole() == RoleNames.MonafasatAdmin)
            {
                blockModel.AgencyCode = User.UserAgency();
            }
            else if (User.UserRole() == RoleNames.MonafasatBlackListCommittee || User.UserRole() == RoleNames.MonafasatBlockListSecritary)
            {
                blockModel.AgencyCode = null;
            }
            blockModel.BranchId = User.UserBranch();
            if (blockModel.IsOldSystem == true)
            {
                blockModel.BlockStatusId = (int)Enums.BlockStatus.ApprovedManager;
            }
            var block  = new SupplierBlock(blockModel.CommercialRegistrationNo, blockModel.CommercialSupplierName, blockModel.ResolutionNumber, (int)Enums.BlockStatus.ApprovedManager, blockModel.BlockTypeId, blockModel.AgencyCode, blockModel.BlockStartDate, blockModel.BlockEndDate, blockModel.Punishment, blockModel.BlockDetails, blockModel.FileName, blockModel.FileNetReferenceId, blockModel.SecretaryFileName, blockModel.SecretaryFileNetReferenceId, blockModel.AdminBlockReason, blockModel.SecretaryBlockReason, blockModel.SupplierTypeId, blockModel.OrganizationTypeId, null, null, true);
            var result = await _blockService.AddBlockAsyn(block);

            return(Ok(result));
        }
Пример #12
0
        public async Task AddSecretaryBlock_Returns_Ok()
        {
            var _supplierBlockModel = new SupplierBlockModel()
            {
                AgencyCode               = "019001000000",
                BlockStatusId            = 5,
                CommercialRegistrationNo = "1010274503",
                ResolutionNumber         = "99",
                SupplierBlockId          = 64,
                SupplierBlockIdString    = "LREqj6Fy4ZfJ4UFZE8jsVg==",
                SupplierTypeId           = 1
            };

            var result = await _blockController.AddSecretaryBlock(_supplierBlockModel);

            var okResult = result as OkResult;

            Assert.NotNull(result);
            Assert.Equal((int)HttpStatusCode.OK, okResult.StatusCode);
        }
Пример #13
0
        public async Task ShouldUpdateBlockAsync()
        {
            ////Mock
            _moqBlockCommands.Setup(x => x.UpdateAsync(It.IsAny <SupplierBlock>()))
            .Returns((SupplierBlock obj) =>
            {
                return(Task.FromResult <SupplierBlock>(obj));
            });

            _moqBlockQueries.Setup(x => x.FindBlockByIdAsync(It.IsAny <int>()))
            .Returns(() =>
            {
                return(Task.FromResult <SupplierBlock>(new SupplierBlock()));
            });


            //=== arrange=========
            var _blockObj = new SupplierBlockModel()
            {
                SupplierBlockId          = 5,
                CommercialRegistrationNo = "SelectedCr1",
                CommercialSupplierName   = "SelectedCrName",
                AgencyCode       = "5",
                BlockDetails     = "BlockDetails",
                FileName         = "FileName",
                BlockEndDate     = DateTime.Now,
                BlockStartDate   = DateTime.Now,
                BlockTypeId      = 1,
                Punishment       = "",
                ResolutionNumber = "456",
                Violation        = "Violation"
            };
            var result = await _sut.UpdateBlockAsync(_blockObj);



            //====== Assert=====
            Assert.NotNull(result);
            Assert.IsType <SupplierBlock>(result);
        }
Пример #14
0
        public async Task <SupplierBlock> AddSecretaryBlock(SupplierBlockModel blockModel)
        {
            blockModel.BlockStatusId = (int)Enums.BlockStatus.ApprovedSecertary;
            if (blockModel.BlockEndDate != null && blockModel.BlockEndDate != DateTime.MinValue && blockModel.BlockEndDate < DateTime.Now)
            {
                throw new BusinessRuleException(Resources.BlockResources.ErrorMessages.DateValidation);
            }

            if (string.IsNullOrEmpty(blockModel.AgencyCode))
            {
                blockModel.AgencyCode = null;
            }

            if (await FindBlockById(blockModel.SupplierBlockId) == null && !(string.IsNullOrEmpty(blockModel.AgencyCode)))
            {
                throw new BusinessRuleException("تم حذف هذا الطلب من مقدم الطلب . لا يمكن استكمال العملية ");
            }

            if (await FindBlockById(blockModel.SupplierBlockId) == null)
            {
                blockModel.IsSecretaryNotify = true;
                return(await AddAdminBlock(blockModel));
            }
            else
            {
                NotificationArguments NotificationArguments = new NotificationArguments
                {
                    BodyEmailArgs    = new object[] { blockModel.CommercialSupplierName },
                    SubjectEmailArgs = new object[] { },
                    PanelArgs        = new object[] { blockModel.CommercialSupplierName },
                    SMSArgs          = new object[] { blockModel.CommercialSupplierName }
                };
                MainNotificationTemplateModel mainNotificationTemplateModelForManger = new MainNotificationTemplateModel(NotificationArguments,
                                                                                                                         $"Block/ManagerBlockDetails?Id={Util.Encrypt(blockModel.SupplierBlockId)}", NotificationEntityType.Block, blockModel.SupplierBlockId.ToString(), 0);
                await _notificationAppService.SendNotificationForUsersByRoleName(NotificationOperations.BlockManager.OperationsToBeApproved.ApproveBlockManager, RoleNames.MonafasatBlackListCommittee, mainNotificationTemplateModelForManger);

                return(await UpdateBlockAsync(blockModel));
            }
        }
Пример #15
0
        public async Task AddBlock_Returns_Throws_AlreadyBlocked()
        {
            var _branchId           = "3";
            var _agencyCode         = "019001000000";
            var _supplierBlockModel = new SupplierBlockModel()
            {
                SupplierBlockId          = 64,
                CommercialRegistrationNo = "1010274503",
                CommercialSupplierName   = "الشركة السعودية لتبادل المعلومات الكترونيا تبادل",
                AdminFileName            = "CR  العملات الأجنبية V2.2 (1).pdf",
                AdminFileNetReferenceId  = "idd_8A7F7375-6A6F-CAC5-8671-6D78C5300000",
                BlockDetails             = "منع دائم - قديم - تاريخ المنع - غدا",
                BlockTypeId      = 1,
                SupplierTypeId   = 1,
                IsOldSystem      = true,
                ResolutionNumber = "99",
                BlockStartDate   = DateTime.Now.AddDays(2),
                Punishment       = "نص العقوبة",
                AgencyCode       = "019001000000",
                BlockStatusId    = 5,
                IsTotallyBlocked = false
            };

            _claims = new Claim[4] {
                new Claim(IdentityConfigs.Claims.Role, RoleNames.MonafasatAdmin),
                new Claim(IdentityConfigs.Claims.isSemiGovAgency, "1"),
                new Claim(IdentityConfigs.Claims.SelectedCR, _agencyCode),
                new Claim(IdentityConfigs.Claims.BranchId, _branchId),
            };
            _blockController = _blockController.WithIdentity(_claims);
            var _expectedMessage = Resources.BlockResources.ErrorMessages.AlreadyBlocked;

            var result = await Assert.ThrowsAsync <BusinessRuleException>(() => _blockController.AddBlock(_supplierBlockModel));

            Assert.NotNull(result);
            Assert.Equal(_expectedMessage, result.Message);
        }
Пример #16
0
        public async Task ShouldAddAdminBlock(bool isSecretaryNotify)
        {
            _moqBlockQueries.Setup(q => q.FindBlockedUser(It.IsAny <BlockSearchCriteria>())).Returns(() =>
            {
                return(Task.FromResult(new QueryResult <SupplierBlockModel>(new List <SupplierBlockModel> {
                }, 0, 1, 10)));
            });

            var _blockObj = new SupplierBlockModel()
            {
                CommercialRegistrationNo = "789645", CommercialSupplierName = "789645312", AdminBlockReason = "8746512", IsSecretaryNotify = isSecretaryNotify
            };

            _moqCommandRepository.Setup(m => m.CreateAsync(It.IsAny <SupplierBlock>())).Returns <SupplierBlock>(r =>
            {
                return(Task.FromResult(new SupplierBlockDefaults().ReturnSupplierBlockDefaults()));
            });

            var result = await _sut.AddAdminBlock(_blockObj);

            Assert.NotNull(result);
            Assert.IsType <SupplierBlock>(result);
            GeneralFields.supplierBlockId = result.SupplierBlockId;
        }
Пример #17
0
        public static async Task <SupplierBlockModel> DeleteBlock(SupplierBlockModel model)
        {
            var result = JsonConvert.DeserializeObject <SupplierBlockModel>(await blockRequest.PostAsync("Block/DeactivateBlock", model));

            return(result);
        }
Пример #18
0
        public static async Task <bool> UpdateBlockDetails(SupplierBlockModel model)
        {
            var result = await blockRequest.PostAsync("Block/UpdateBlock", model);

            return(true);
        }
Пример #19
0
 public async Task SecretaryRejectionReason([FromBody] SupplierBlockModel blockSearchCriteria)
 {
     await _blockService.SecretaryRejectionReason(blockSearchCriteria.SupplierBlockId, blockSearchCriteria.SecretaryRejectionReason);
 }
Пример #20
0
        public async Task <SupplierBlockModel> GetBlockByIdForSupplier(int supplierBlockId)
        {
            SupplierBlockModel block = await _blockService.FindBlockById(supplierBlockId);

            return(block);
        }
Пример #21
0
        public async Task <IActionResult> UpdateBlock([FromBody] SupplierBlockModel blockModel)
        {
            var result = await _blockService.UpdateBlockAsync(blockModel);

            return(Ok(result));
        }