private XElement ContractAward()
        {
            var lot = _notice.ObjectDescriptions.FirstOrDefault();

            if (lot == null)
            {
                return(null);
            }

            return(TedHelpers.Element("AWARD_CONTRACT",
                                      TedHelpers.Element("CONTRACT_NO", lot.AwardContract?.AwardedContract?.ContractNumber),
                                      _notice.LotsInfo.DivisionLots ? TedHelpers.Element("LOT_NO", lot.LotNumber.ToString()) : null,
                                      TedHelpers.PElement("TITLE", lot.AwardContract?.AwardedContract?.ContractTitle),
                                      TedHelpers.Element("AWARDED_CONTRACT",
                                                         TedHelpers.DateElement("DATE_CONCLUSION_CONTRACT", lot.AwardContract?.AwardedContract?.ConclusionDate <= DateTime.Now ? lot.AwardContract?.AwardedContract?.ConclusionDate : DateTime.Now),
                                                         TedHelpers.Element("CONTRACTORS",
                                                                            lot.AwardContract?.AwardedContract?.Contractors?.Count > 1 ? TedHelpers.Element("AWARDED_TO_GROUP") : TedHelpers.Element("NO_AWARDED_TO_GROUP"),
                                                                            lot.AwardContract?.AwardedContract?.Contractors?.Select((contractor, a) =>
                                                                                                                                    TedHelpers.Element("CONTRACTOR",
                                                                                                                                                       TedHelpers.ADDRS5(contractor),
                                                                                                                                                       contractor.IsSmallMediumEnterprise ? TedHelpers.Element("SME") : TedHelpers.Element("NO_SME")))
                                                                            ),
                                                         TedHelpers.Element("VALUES",
                                                                            lot.AwardContract?.AwardedContract?.FinalTotalValue.Value > 0 ?
                                                                            TedHelpers.ElementWithAttribute("VAL_TOTAL", "CURRENCY", lot.AwardContract.AwardedContract.FinalTotalValue.Currency, lot.AwardContract.AwardedContract.FinalTotalValue.Value)
                                : null))));
        }
 /// <summary>
 /// Section VI: Complementary information
 /// </summary>
 /// <returns>The COMPLEMENTARY_INFO XElement</returns>
 private XElement ComplementaryInformation()
 {
     return(TedHelpers.Element("COMPLEMENTARY_INFO",
                               TedHelpers.PElement("INFO_ADD", _notice.ComplementaryInformation?.AdditionalInformation),
                               TedHelpers.ADDRS6("ADDRESS_REVIEW_BODY", _notice.ProceduresForReview?.ReviewBody),
                               TedHelpers.PElement("REVIEW_PROCEDURE", _notice.ProceduresForReview?.ReviewProcedure),
                               TedHelpers.DateElement("DATE_DISPATCH_NOTICE", DateTime.Now)));
 }
        private static List <XElement> NewValue(Change change)
        {
            List <XElement> newValue;

            if (change.NewText != null && change.NewText.Length > 0 && !string.IsNullOrEmpty(change.NewText[0]))
            {
                newValue = new List <XElement> {
                    TedHelpers.PElement("TEXT", change.NewText)
                };
            }
            else if (change.NewDate != null && change.NewDate != DateTime.MinValue)
            {
                newValue = new List <XElement> {
                    TedHelpers.DateElement("DATE", change.NewDate)
                };
            }
            else if (change.NewMainCpvCode != null && !string.IsNullOrEmpty(change.NewMainCpvCode.Code))
            {
                newValue = new List <XElement> {
                    TedHelpers.Element("CPV_MAIN",
                                       TedHelpers.ElementWithAttribute("CPV_CODE", "CODE", change.NewMainCpvCode.Code),
                                       change.NewMainCpvCode.VocCodes?.Select(x => TedHelpers.ElementWithAttribute("CPV_SUPPLEMENTARY_CODE", "CODE", x.Code)))
                };
            }
            else if (change.NewAdditionalCpvCodes != null &&
                     change.NewAdditionalCpvCodes.Count > 0 &&
                     change.NewAdditionalCpvCodes.Any(x => !string.IsNullOrEmpty(x.Code)))
            {
                newValue = change.NewAdditionalCpvCodes.Select(x =>
                                                               TedHelpers.Element("CPV_ADDITIONAL",
                                                                                  TedHelpers.ElementWithAttribute("CPV_CODE", "CODE", x.Code),
                                                                                  x.VocCodes?.Select(y => TedHelpers.ElementWithAttribute("CPV_SUPPLEMENTARY_CODE", "CODE", y.Code)))
                                                               ).ToList();
            }
            else
            {
                newValue = new List <XElement> {
                    TedHelpers.Element("NOTHING")
                };
            }

            return(newValue);
        }
        private IEnumerable <XElement> Duration(TimeFrame timeFrame, string[] justificationIsOverFourYears, string[] justificationIsOverEightYears)
        {
            if (timeFrame == null)
            {
                yield break;
            }

            switch (timeFrame.Type)
            {
            case TimeFrameType.Days:
                yield return(TedHelpers.ElementWithAttribute("DURATION", "TYPE", "DAY", timeFrame.Days));

                break;

            case TimeFrameType.Months:
                yield return(TedHelpers.ElementWithAttribute("DURATION", "TYPE", "MONTH", timeFrame.Months));

                break;

            case TimeFrameType.BeginAndEndDate:
                yield return(TedHelpers.DateElement("DATE_START", timeFrame.BeginDate));

                yield return(TedHelpers.DateElement("DATE_END", timeFrame.EndDate));

                break;

            default:
                throw new HilmaMalformedRequestException("Undefined is not allowed value for time frame type");
            }

            if (justificationIsOverFourYears != null && justificationIsOverFourYears.HasAnyContent() && timeFrame.IsOverFourYears)
            {
                yield return(TedHelpers.PElement("JUSTIFICATION", justificationIsOverFourYears));
            }
            if (justificationIsOverEightYears != null && justificationIsOverEightYears.HasAnyContent() && timeFrame.IsOverEightYears)
            {
                yield return(TedHelpers.PElement("JUSTIFICATION", justificationIsOverEightYears));
            }
        }