public async Task AddEditTechnicalDeclerationsTemplate(EditConditionTemplateSeventhSectionModel model, int branchId)
        {
            Tender tender = await _tenderQueries.FindTenderWithConditionsTemplateTechnicalOutputs(Util.Decrypt(model.EncryptedTenderId), branchId);

            if (tender == null)
            {
                throw new UnHandledAccessException(Resources.SharedResources.ErrorMessages.YouHaveNoAccess);
            }
            IsValidToAddEditTechnicalDeclerationsTemplate(tender, model);
            UpdateTenderConditionTemplateStatusId(tender, Enums.TenderConditoinsStatus.TechnicalDeclerations);
            tender.UpdateConditionsTemplateSeventhStep(
                tenderConditionsTemplateTechnicalOutput: model.TenderConditionsTemplateOutputs != null ? model.TenderConditionsTemplateOutputs.Select(a => new TenderConditionsTemplateTechnicalOutput
                                                                                                                                                      (
                                                                                                                                                          tenderConditionsTemplateTechnicalOutputId: a.TenderConditionsTemplateTechnicalOutputId,
                                                                                                                                                          outState: a.OutputStage,
                                                                                                                                                          outputName: a.OutputName,
                                                                                                                                                          outDescriptions: a.OutputDescriptions,
                                                                                                                                                          outDeliveryTime: a.OutputDeliveryTime
                                                                                                                                                      )).ToList() : new List <TenderConditionsTemplateTechnicalOutput>(),
                tenderConditionsTemplateTechnicalDelrations: model.TechnicalDeclrations != null ? model.TechnicalDeclrations.Select(a => new TenderConditionsTemplateTechnicalDeclration
                                                                                                                                    (
                                                                                                                                        tenderConditionsTemplateTechnicalDeclrationId: a.TenderConditionsTemplateTechnicalDeclrationId,
                                                                                                                                        term: a.Term,
                                                                                                                                        decleration: a.Decleration
                                                                                                                                    )).ToList() : new List <TenderConditionsTemplateTechnicalDeclration>(),
                projectsScope: model.ProjectsScope,
                worksProgram: model.WorksProgram,
                workLocationDetails: model.WorkLocationDetails,
                servicesAndWorkImplementationsMethod: model.ServicesAndWorkImplementationsMethod
                );
            await _tenderCommands.UpdateAsync(tender);
        }
        public void IsValidToUpdateConditionsTemplateSeventhStep(Tender tender, EditConditionTemplateSeventhSectionModel model, bool ValidatationFromNextStep = false)
        {
            var ShowGeneralOnly = tender.TenderActivities.Where(a => a.IsActive == true).Select(a => a.Activity.Activitytemplate.ActivitytemplatId).Distinct().Count() > 1;

            IsValidToUpdateConditionsTemplateThirdStep(tender, null, true);

            var listOfSections = tender.TenderActivities.SelectMany(a => a.Activity.Activitytemplate.ConditionTemplateActivities).Select(a => a.ConditionsTemplateSectionId).Distinct().ToList();

            if (!(tender.ConditionTemplateStageStatusId == (int)Enums.TenderConditoinsStatus.EvaluateOffers ||
                  tender.ConditionTemplateStageStatusId == (int)Enums.TenderConditoinsStatus.ContractingRequirments ||
                  tender.ConditionTemplateStageStatusId == (int)Enums.TenderConditoinsStatus.Specifications))
            {
                throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.MustFillPreviousInformation);
            }
            if (listOfSections.Contains((int)Enums.ConditionsTemplateSections.Outputs) && !ShowGeneralOnly)
            {
                if ((!ValidatationFromNextStep && ((model?.TenderConditionsTemplateOutputs?.Count ?? 0) == 0)) || (ValidatationFromNextStep && (tender.TenderConditionsTemplate?.TenderConditionsTemplateTechnicalOutputs?.Count ?? 0) == 0))
                {
                    var value = Resources.TenderResources.DisplayInputs.TenderConditionsTemplateOutputs;
                    throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
                }
            }
            if (listOfSections.Contains((int)Enums.ConditionsTemplateSections.ProjectWorkScope))
            {
                if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.ProjectsScope)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.ProjectsScope)))
                {
                    var value = Resources.TenderResources.DisplayInputs.ProjectsScope;
                    throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
                }
            }
            if (listOfSections.Contains((int)Enums.ConditionsTemplateSections.WorkProgram))
            {
                if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.WorksProgram)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.WorksProgram)))
                {
                    var value = Resources.TenderResources.DisplayInputs.WorksProgram;
                    throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
                }
            }
            if (listOfSections.Contains((int)Enums.ConditionsTemplateSections.WorkLocation))
            {
                if ((!ValidatationFromNextStep && string.IsNullOrEmpty(model?.WorkLocationDetails)) || (ValidatationFromNextStep && string.IsNullOrEmpty(tender.TenderConditionsTemplate?.WorkLocationDetails)))
                {
                    var value = Resources.TenderResources.DisplayInputs.WorkLocationDetails;
                    throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
                }
            }
        }
        private void IsValidToAddEditTechnicalDeclerationsTemplate(Tender tender, EditConditionTemplateSeventhSectionModel model)
        {
            List <int> listOfSections = Array.ConvertAll(model.ListOfSections.Split(','), int.Parse).ToList();

            if (!(tender.ConditionTemplateStageStatusId == (int)Enums.TenderConditoinsStatus.EvaluateOffers ||
                  tender.ConditionTemplateStageStatusId == (int)Enums.TenderConditoinsStatus.ContractingRequirments ||
                  tender.ConditionTemplateStageStatusId == (int)Enums.TenderConditoinsStatus.Specifications))
            {
                throw new BusinessRuleException(Resources.TenderResources.ErrorMessages.MustFillPreviousInformation);
            }
            if (model.VersionId >= (int)Enums.ActivityVersions.Sprint7Activities && model.TechnicalDeclrations == null)
            {
                var value = Resources.TenderResources.DisplayInputs.TermsAndDefinitions;
                throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
            }
            if (listOfSections.Contains((int)Enums.ConditionsTemplateSections.Outputs) && !model.ShowGeneralOnly && model.TenderConditionsTemplateOutputs == null)
            {
                var value = Resources.TenderResources.DisplayInputs.TenderConditionsTemplateOutputs;
                throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
            }
            if (string.IsNullOrEmpty(model?.ProjectsScope))
            {
                var value = Resources.TenderResources.DisplayInputs.ProjectsScope;
                throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
            }
            if (string.IsNullOrEmpty(model?.WorksProgram))
            {
                var value = Resources.TenderResources.DisplayInputs.WorksProgram;
                throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
            }
            if (string.IsNullOrEmpty(model?.WorkLocationDetails))
            {
                var value = Resources.TenderResources.DisplayInputs.WorkExcutionlocation;
                throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
            }
            if (listOfSections.Contains((int)Enums.ConditionsTemplateSections.ImplementaionMethod) && string.IsNullOrEmpty(model?.ServicesAndWorkImplementationsMethod))
            {
                var value = Resources.TenderResources.DisplayInputs.ServicesAndWorkImplementationsMethod;
                throw new BusinessRuleException(Resources.TenderResources.DisplayInputs.PleaseEnterValueOf + value);
            }
        }