public AnnouncementSupplierTemplate ExtendAnnouncementSupplierTemplateData(ExtendAnnouncementSupplierTemplateModel model, List <AnnouncementSuppliersTemplateAttachment> attachments, int userId)
 {
     TemplateExtendMechanism = model.TemplateExtendMechanism;
     AnnouncementName        = model.AnnouncementSupplierTemplateName;
     AnnouncementTemplateSuppliersListTypeId = model.AnnouncementTemplateSuppliersListTypeId;
     TenderTypesId = model.TenderTypesId;
     IntroAboutAnnouncementTemplate = model.IntroAboutAnnouncementTemplate;
     Descriptions                    = model.Descriptions;
     Details                         = model.Details;
     IsEffectiveList                 = model.IsEffectiveList;
     EffectiveListDate               = model.EffectiveListDate;
     ActivityDescription             = model.ActivityDescription;
     InsidKsa                        = model.InsideKsa;
     StatusId                        = (int)Enums.AnnouncementSupplierTemplateStatus.Approved;
     BranchId                        = model.BranchId;
     RequirementConditionsToJoinList = model.RequirementConditionsToJoinList;
     IsRequiredAttachmentToJoinList  = model.IsRequiredAttachmentToJoinList;
     RequiredAttachment              = model.RequiredAttachment;
     AgencyCode                      = model.AgencyCode;
     AgencyAddress                   = model.AgencyAddress;
     AgencyFax                       = model.AgencyFax;
     AgencyPhone                     = model.AgencyPhone;
     AgencyEmail                     = model.AgencyEmail;
     UpdateAnnouncementSupplierTemplateRelations(model.AreasIds, model.ActivityIds, model.ConstructionWorkIds, model.MaintenanceRunnigWorkIds, model.InsideKsa, model.Details, model.ActivityDescription, model.CountriesIds);
     UpdateSuppliersTemplateAttachments(attachments, userId, false);
     EntityUpdated();
     return(this);
 }
예제 #2
0
        public async Task GetAnnouncementByIdForExtendAnnouncement_Returns_Data()
        {
            var _announcementIdString = Util.Encrypt(13);
            var _expectedResult       = new ExtendAnnouncementSupplierTemplateModel()
            {
                ActivityDescription              = "NN",
                AgencyCode                       = "022001000000",
                AnnouncementId                   = 13,
                AnnouncementIdString             = "4D*@@**CkYL*@@**L*@@**yHtLTllLUmsg==",
                AnnouncementSupplierTemplateName = "اعلان اول",
                CreatedBy    = "مدخل وسكرتير نظام المنافسات والمشتريات | 5555555555",
                BranchId     = 4,
                InsideKsa    = true,
                TenderTypeId = 2
            };
            var result = await _announcementController.GetAnnouncementByIdForExtendAnnouncement(_announcementIdString);

            Assert.NotNull(result);
            Assert.IsType <ExtendAnnouncementSupplierTemplateModel>(result);
            Assert.Equal(_expectedResult.ActivityDescription, result.ActivityDescription);
            Assert.Equal(_expectedResult.AgencyCode, result.AgencyCode);
            Assert.Equal(_expectedResult.AnnouncementId, result.AnnouncementId);
            Assert.Equal(_expectedResult.AnnouncementIdString, result.AnnouncementIdString);
            Assert.Equal(_expectedResult.BranchId, result.BranchId);
            Assert.True(result.InsideKsa);
        }
        private void IsValidToExtendAnnouncementSupplier(ExtendAnnouncementSupplierTemplateModel announcement)
        {
            if (string.IsNullOrEmpty(announcement.TemplateExtendMechanism) || string.IsNullOrEmpty(announcement.AnnouncementSupplierTemplateName) || string.IsNullOrEmpty(announcement.IntroAboutAnnouncementTemplate) || string.IsNullOrEmpty(announcement.Descriptions))
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.EnterRequiredData);
            }
            if (announcement.TenderTypesId == null || !announcement.TenderTypesId.Any())
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.EnterTenderTypes);
            }
            if (announcement.InsideKsa)
            {
                if (announcement.AreasIds == null || !announcement.AreasIds.Any())
                {
                    throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.EnterTenderAreas);
                }
            }
            else
            {
                if (announcement.CountriesIds == null || !announcement.CountriesIds.Any())
                {
                    throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.EnterTenderCountries);
                }
            }

            if (announcement.ActivityIds == null || !announcement.ActivityIds.Any())
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.ActivityIdRequired);
            }

            if (announcement.IsEffectiveList && announcement.EffectiveListDate == null)
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.EffectiveListDateRequired);
            }

            if (announcement.IsEffectiveList && announcement.EffectiveListDate.Value.Date < DateTime.Now.Date)
            {
                throw new BusinessRuleException(Resources.SharedResources.ErrorMessages.DateLessThanToday);
            }

            if (announcement.IsRequiredAttachmentToJoinList && announcement.RequiredAttachment == null)
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.AnnouncementRequiredAttachment);
            }

            if (string.IsNullOrEmpty(announcement.AgencyAddress) || string.IsNullOrEmpty(announcement.AgencyFax) || string.IsNullOrEmpty(announcement.AgencyPhone) || string.IsNullOrEmpty(announcement.AgencyEmail))
            {
                throw new BusinessRuleException(Resources.AnnouncementResources.ErrorMessages.AgencyRequired);
            }
        }
        private async Task SendNotificationAfterExtendAnnouncementTemplate(ExtendAnnouncementSupplierTemplateModel extendAnnouncement)
        {
            var AcceptedSuppliers = await _announcementQueries.GetAcceptedAnnouncementSuppliers(extendAnnouncement.AnnouncementId);

            if (AcceptedSuppliers.Any())
            {
                MainNotificationTemplateModel mainNotificationTemplateModelForSupplier;
                NotificationArguments         NotificationArguments = new NotificationArguments();
                NotificationArguments.BodyEmailArgs      = new object[] { extendAnnouncement.ReferenceNumber, extendAnnouncement.TemplateExtendMechanism };
                NotificationArguments.SubjectEmailArgs   = new object[] { };
                NotificationArguments.PanelArgs          = new object[] { extendAnnouncement.ReferenceNumber };
                NotificationArguments.SMSArgs            = new object[] { extendAnnouncement.ReferenceNumber };
                mainNotificationTemplateModelForSupplier = new MainNotificationTemplateModel(NotificationArguments, $"AnnouncementSuppliersTemplate/AnnouncementSuppliersTemplateDetailsForSuppliers?announcementIdString={Util.Encrypt(extendAnnouncement.AnnouncementId)}", NotificationEntityType.Announcement, extendAnnouncement.AnnouncementId.ToString(), 0);
                await _notificationAppService.SendNotificationForSuppliers(NotificationOperations.ExtendAnnouncementTemplate.OperationsOnExtendAnnouncement.SendNotificationToAcceptedSuppliers, AcceptedSuppliers, mainNotificationTemplateModelForSupplier);
            }
        }
        public async Task <ExtendAnnouncementSupplierTemplateModel> ExtendAnnouncementTemplate(ExtendAnnouncementSupplierTemplateModel announcementModel)
        {
            IsValidToExtendAnnouncementSupplier(announcementModel);
            int createdById = _httpContextAccessor.HttpContext.User.UserId();

            Check.ArgumentNotNull(nameof(announcementModel), announcementModel);
            List <AnnouncementSuppliersTemplateAttachment> attachments = new List <AnnouncementSuppliersTemplateAttachment>();

            if (announcementModel.Attachments != null)
            {
                foreach (var item in announcementModel.Attachments)
                {
                    attachments.Add(new AnnouncementSuppliersTemplateAttachment(item.Name, item.FileNetReferenceId, item.AttachmentTypeId));
                }
            }
            var announcementSupplierTemplate = await _announcementQueries.GetAnnouncementByIdForCreationStep(Util.Decrypt(announcementModel.AnnouncementIdString));

            announcementModel.ReferenceNumber = announcementSupplierTemplate.ReferenceNumber;
            announcementSupplierTemplate.ExtendAnnouncementSupplierTemplateData(announcementModel, attachments, createdById);
            await _announcementCommands.UpdateAnnouncementSupplierTemplate(announcementSupplierTemplate);

            await _announcementCommands.SaveChangesAsync();

            await SendNotificationAfterExtendAnnouncementTemplate(announcementModel);

            return(announcementModel);
        }
        public async Task <ExtendAnnouncementSupplierTemplateModel> ExtendAnnouncementTemplate([FromBody] ExtendAnnouncementSupplierTemplateModel announcementModel)
        {
            var result = await _announcementSupplierTemplateAppService.ExtendAnnouncementTemplate(announcementModel);

            return(result);
        }