Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have to compare the IEnumerable data from UI and the IEnumerable data from SQL Server 2008 and have to insert/update the new elements from UI to DB and delete the elements from DB based on UI data.
 
I am having Distribution_X_ListType table in DB as:
 
    DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
    1              2          84528          NULL         NULL 
    1              3          NULL           8051         NULL
    1              5          NULL           NULL         319
I am having an interface in a project as follows:
 
    public interface IDistributionList : IEntity
        {
            string Name { get; set; }
            bool ActiveFlag { get; set; }
            ...........................
            ...........................
            IEnumerable<IDistributionListType> ListTypes { get; set; }        
        }
 
The another interface is:
 
    public interface IDistributionListType
    {
        int? DistributionID { get; set; }
        int ListTypeID { get; set; }
        int EmployeeNumber { get; set; }
        int DepartmentID { get; set; }
        int LocationID { get; set; }
    }
 
In another project I am having Save function as follows:
 
    public int Save(IDistributionList distributionList)
            {
                SqlDataReader reader = null;            
                int rowsaffected = 0;
                try
                {
                    sqlcommand = new SqlCommand("spGetDistributionListTypeByID", con);  //spGetDistributionListTypeByID - This SP returns all the members from Distribution_X_ListType table for the given distribution ID
                    sqlcommand.CommandType = CommandType.StoredProcedure;
                    sqlcommand.Parameters.AddWithValue("@Distribution_ID", distributionList.ID);
                    
                    reader = sqlcommand.ExecuteReader();
    
                    while (reader.Read())
                    {
                          ????Value Should be stored in an IDistributionListType variable,say IDistributionListTypeFromDB 
                    }
                    ????IDistributionListType from function parameter(Lets say from UI) should be compared with the above IDistributionListTypeFromDB data.
                    ????Insert/Delete should be done in DB by comparing the data.
                 }
             }
 
Let the value of IDistributionListType from UI:
 
    DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
    1              2          84528          NULL         NULL 
    1              5          NULL           NULL         64 

 
Let the value of IDistributionListType from DB:
 
    DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
    1              2          84528          NULL         NULL 
    1              3          NULL           8051         NULL
    1              5          NULL           NULL         319
 
I need to update the DB with the data from UI. I am having two more SPs as :
 
    spInsertUpdateDistributionListType - Insert/Update Distribution_X_ListType table  based on DistributionID and listtypeID
    spDeleteDistributionListType - Delete Distribution_X_ListType table based on DistributionID and listtypeID
 
I don't know how to code in ???? areas. Anybody please helpout. Thanks in advance.
Posted 23-Jan-13 0:35am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You must be having a concrete class that implements the interface. You will have to create object of that class and add data to it. This object can then be added to the interface list you have.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100