public void IsValidToUpdateConditionsTemplateSecondStep(Tender tender, EditConditionTemplateSecondSectionModel model, bool ValidatationFromNextStep = false)
 {
     if (tender == null)
     {
         throw new AuthorizationException();
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.Description)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.Description)))
     {
         var value = Resources.TenderResources.DisplayInputs.TenderDescription;
         throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
     }
     if (model != null && !model.HideCerificatesIDs)
     {
         if ((!ValidatationFromNextStep && ((model?.CerificatesIDs?.Count ?? 0) == 0)) || (ValidatationFromNextStep && (tender.TenderConditionsTemplate?.TemplateCertificates?.Count ?? 0) == 0))
         {
             var value = Resources.TenderResources.DisplayInputs.SystemCertificates;
             throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseSelect + value);
         }
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.AgentName)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.AgentName)))
     {
         var value = Resources.SharedResources.DisplayInputs.Name;
         throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.AgentPhone)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.AgentPhone)))
     {
         throw new BusinessRuleException(Resources.CommitteeResources.ErrorMessages.InvalidPhoneNumber);
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.AgentFax)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.AgentFax)))
     {
         throw new BusinessRuleException(Resources.CommitteeResources.ErrorMessages.InvalidFaxNumber);
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.AgentJob)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.AgentJob)))
     {
         var value = Resources.SharedResources.DisplayInputs.Job;
         throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.AgentEmail)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.AgentEmail)))
     {
         throw new BusinessRuleException(Resources.CommitteeResources.ErrorMessages.EmailInvalid);
     }
     if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.AgencyDecalration)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.AgencyDecalration)))
     {
         var value = Resources.TenderResources.DisplayInputs.AgencyDecalration;
         throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
     }
 }
        public async Task AddEditIntroductionTemplate(EditConditionTemplateSecondSectionModel model, int branchId)
        {
            Tender tender = await _tenderQueries.FindTenderWithConditionsTemplateIntroductionById(Util.Decrypt(model.EncryptedTenderId), branchId);

            if (tender == null)
            {
                throw new UnHandledAccessException(Resources.SharedResources.ErrorMessages.YouHaveNoAccess);
            }
            if (tender.TenderConditionsTemplate == null)
            {
                tender.CreateConditionsTemplate();
            }
            IsValidToAddEditIntroductionTemplate(tender, model);
            UpdateTenderConditionTemplateStatusId(tender, Enums.TenderConditoinsStatus.GeneralStage);

            tender.TenderConditionsTemplate.UpdateConditionsTemplateSecondStep(model.AgencyDecalration, model.Description, model.AgentName, model.AgentJob, model.AgentFax, model.AgentPhone,
                                                                               model.TenderFragmentation, model.HideTenderFragmentation, model.AgentEmail, model.CerificatesIDs, model.HideCerificatesIDs);
            await _tenderCommands.UpdateAsync(tender);
        }