Question

I need your help please.

I have this method:

protected void btnDocumentType_Click(object sender, EventArgs e)
        {

            DocumentApplicationCategoryManager DACM = new DocumentApplicationCategoryManager();
            IkubInfo.NE.Domain.DocumentApplicationCategory DAC = new Domain.DocumentApplicationCategory();

            DAC.DocumentType = new DocumentTypeManager().GetById(new Guid(cboDocumentType.SelectedValue));
            DAC.ApplicationCategory = Entity;

            Entity.DocumentApplicationCategory.Add(DAC);

            DACM.Save(DAC);
            DACM.Session.CommitChanges();
            SetUIValues();
        }

This is the method for the ADD button, which allows the user to add a value in the grid. I need to check that if the value that the user is trying to add is saved once, it cannot be saved twice. I need to validate it and show user an error message but I don't know how to do this. I guess that I have to put an "if" condition before this line:

DAC.DocumentType = new DocumentTypeManager().GetById(new Guid(cboDocumentType.SelectedValue));

Any idea ? Your help would be appreciated. Thanks in advance :)

Was it helpful?

Solution

protected void btnDocumentType_Click(object sender, EventArgs e)
        {

            DocumentApplicationCategoryManager DACM = new DocumentApplicationCategoryManager();
            IkubInfo.NE.Domain.DocumentApplicationCategory DAC = new Domain.DocumentApplicationCategory();

            DAC.DocumentType = new DocumentTypeManager().GetById(new Guid(cboDocumentType.SelectedValue));
            DAC.ApplicationCategory = Entity;

//Check here from DocumentApplicationCategory, Whether DAC.DocumentType and Entity Exists or not, if does not exists then allow to come in 
        if(CHECK_HERE)
        {
                Entity.DocumentApplicationCategory.Add(DAC);

                DACM.Save(DAC);
                DACM.Session.CommitChanges();
        }
            SetUIValues();
        }

refer the comments: at place of CHECK_HERE, Put your condition to confirm the data your are trying to insert already exists or not.

OTHER TIPS

What you need to do is to check for every value in the combobox if the value inserted exists or not. To do so, you need to create a loop with a condition of type HasNext or IsNull and inside th loop you will use your If statement that will compare the values of the ID (from what i have understood from your code) .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top