Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EdiSegment with list of EdiElement #121

Closed
dinmukhamed09 opened this issue Feb 4, 2019 · 10 comments
Closed

EdiSegment with list of EdiElement #121

dinmukhamed09 opened this issue Feb 4, 2019 · 10 comments

Comments

@dinmukhamed09
Copy link

dinmukhamed09 commented Feb 4, 2019

Hi,

I have issue with Segment exist list of values.

Example:

ATR+NEW+PRIO:N'
ATR+NEW+TGIC:465+TGNO:716073+TGPC:SVX'
ATR+NEW+ACCS:A+BGCL:Y+BRDP:KBP+OFFP:TSE+PRIL:N'

I want get List of values like:

[EdiSegment, EdiPath("ATR")]
public class Main
{
     List<Information> Informations { get; set; }
}

Attention edivalue exist n counter

public class Information
{
    [EdiValue("X(4)", Path = "ATR/n/0")]
    public string Code{ get; set; }

    [EdiValue("X(256)", Path = "ATR/n/1")]
    public string Value{ get; set; }
}

1st Main:
Information[0].Code = PRIO

2nd Main:
Information[0].Code = TGIC
Information[0].Code = TGNO
Information[0].Code = TGPC

3rd Main:
Information[0].Code = ACCS
Information[0].Code = BGCL
Information[0].Code = BRDP
Information[0].Code = PRIL

@cleftheris cleftheris changed the title Edisegment inside list of edielement EdiSegment inside list of EdiElement Feb 4, 2019
@cleftheris
Copy link
Contributor

If I understand this correctly you need to bind a repeating Element to a list of elements.

This feature is not supported yet. As a workaround you can make multiple subclass of Information or multiple properties of Code and Value inside the Main class (ATR).

[EdiSegment, EdiPath("ATR")]
public class Main
{
     [EdiElement, EdiPath("ATR/0")]
     Information Information { get; set; }
     [EdiElement, EdiPath("ATR/1")]
     Information1 Information1 { get; set; }
     [EdiElement, EdiPath("ATR/2")]
     Information2 Information2 { get; set; }
}
public class Information
{
    [EdiValue("X(4)", Path = "ATR/0/0")]
    public virtual string Code{ get; set; }

    [EdiValue("X(256)", Path = "ATR/0/1")]
    public virtual string Value { get; set; }
}
public class Information1 : Information
{
    [EdiValue("X(4)", Path = "ATR/1/0")]
    public virtual string Code{ get; set; }

    [EdiValue("X(256)", Path = "ATR/1/1")]
    public virtual string Value { get; set; }
}
public class Information2 : Information
{
    [EdiValue("X(4)", Path = "ATR/2/0")]
    public virtual string Code{ get; set; }

    [EdiValue("X(256)", Path = "ATR/2/1")]
    public virtual string Value { get; set; }
}

Related to #105

@dinmukhamed09
Copy link
Author

This list can reach up to 99 items. I have to create Information class 99 times?
Do you have workaround for that case?

@cleftheris cleftheris changed the title EdiSegment inside list of EdiElement EdiSegment with list of EdiElement Feb 12, 2019
@cleftheris
Copy link
Contributor

Checkout this example https://github.com/indice-co/EDI.Net/blob/master/test/indice.Edi.Tests/Models/EdiFact_Issue121_ElementList.cs

and I will be posting a beta release 1.9 soon

@dinmukhamed09
Copy link
Author

Hi,

Thank you works good. When you release new version?

@cleftheris
Copy link
Contributor

Just published 1.9 to nuget

@dinmukhamed09
Copy link
Author

dinmukhamed09 commented Feb 19, 2019

I used in project. And have problem.

ATR+NEW+BRDC:J+BRDS;B+BRDT:S+BRDY:DGR

    [EdiSegment, EdiPath( "ATR")]
    public class Main
    {
        [EdiPath("ATR/*")]
        public List<Information> Informations { get; set; }
    }

    [EdiElement]
    public class Information
    {
        [EdiValue("X(4)", Path = "*/*/0")]
        public string Code { get; set; }

        [EdiValue("X(4)", Path = "*/*/1")]
        public string Value{ get; set; }
    }

I Have error.
First item can't get. And the latest not show and some values is incorrect.
I think because, first element doesn't exist a value

@cleftheris
Copy link
Contributor

cleftheris commented Feb 19, 2019

You have to give me a complete sample and a model. Because for this transmission the feature works as expected and binds everything.

UNB+UNOD'
UNH+000001'
ATR+NEW+PRIO:N'
ATR+NEW+TGIC:465+TGNO:716073+TGPC:SVX'
ATR+NEW+ACCS:A+BGCL:Y+BRDP:KBP+OFFP:TSE+PRIL:N'
UNT+3'
UNZ+1'

Here is the test

public void EdiFact_ElementList() {

02f48c0f-cac6-4dc3-b17d-8e33d6a3dc8f png

@dinmukhamed09
Copy link
Author

dinmukhamed09 commented Feb 21, 2019

I saw. Try use that.

    public class EdiFact_Issue121_ElementList
    {
        public Message Msg { get; set; }

        [EdiMessage]
        public class Message
        {
            [EdiCondition("NEW", CheckFor = EdiConditionCheckType.Equal, Path = "ATR/0/0")]
            public List<Attribute> Attributes { get; set; }

            [EdiCondition("V", CheckFor = EdiConditionCheckType.Equal, Path = "ATR/1/0")]
            public List<Criteria> Attributes1 { get; set; }
        }

        [EdiSegment, EdiPath("ATR")]
        public class Attribute
        {
            [EdiPath("ATR/*")]
            public List<Information> Infos { get; set; }
        }

        [EdiElement]
        public class Information
        {
            [EdiValue("X(4)", Path = "*/*/0")]
            public string Code { get; set; }

            [EdiValue("X(256)", Path = "*/*/1")]
            public string Value { get; set; }
        }

        [EdiSegmentGroup("ATR")]
        public class Criteria
        {
            [EdiValue("X(100)", Path = "LTS/0", Mandatory = true)]
            public string Value { get; set; }
        }
    }
UNB+UNOD'
UNH+000001'
ATR+NEW+PRIO:N'
ATR+NEW+TGIC:465+TGNO:716073+TGPC:SVX'
ATR+NEW+ACCS:A+BGCL:Y+BRDP:KBP+OFFP:TSE+PRIL:N'
ATR++V'
LTS+�2'
UNT+3'
UNZ+1'

@cleftheris
Copy link
Contributor

cleftheris commented Oct 11, 2019

@dinmukhamed09 I have revisited the case and finally figured this out!! Now the deserializer can work even the last case!

The following model will bind everything just fine

    public class EdiFact_Issue121_ElementList_Conditions
    {
        public Message Msg { get; set; }

        [EdiMessage]
        public class Message
        {
            [EdiCondition("NEW", CheckFor = EdiConditionCheckType.Equal, Path = "ATR/0/0")]
            public List<Criteria> Attributes { get; set; }

            [EdiCondition("V", CheckFor = EdiConditionCheckType.Equal, Path = "ATR/1/0")]
            public List<Criteria> Attributes1 { get; set; }
        }

        [EdiSegment, EdiPath("ATR")]
        public class Attribute
        {
            [EdiPath("ATR/*")]
            public List<Information> Infos { get; set; }
        }

        [EdiElement]
        public class Information
        {
            [EdiValue("X(4)", Path = "*/*/0")]
            public string Code { get; set; }

            [EdiValue("X(256)", Path = "*/*/1")]
            public string Value { get; set; }
        }

        [EdiSegmentGroup("ATR", "LTS")]
        public class Criteria : Attribute
        {
            public LTS LTS { get; set; }
        }

        [EdiSegment, EdiPath("LTS")]
        public class LTS
        {
            [EdiValue("X(100)", Path = "LTS/0", Mandatory = true)]
            public string Value { get; set; }
        }
    }

Check the Test here

public void EdiFact_ElementList_WithConditions() {

@cleftheris
Copy link
Contributor

I will post a new version v1.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants