@@ -85,63 +85,88 @@ public ActionResult Download()
8585
8686 public ActionResult UploadSelectedRows ( int [ ] rowIds )
8787 {
88- ComponentDataModel compData = Session [ "ComponentData" ] as ComponentDataModel ;
89-
90- //check for dublicates
91- int [ ] noDuplicateIds = CheckDuplicates ( compData . Data , rowIds ) ;
92-
9388 string result = "" ;
94-
95- if ( noDuplicateIds . Length == 0 )
89+ if ( rowIds != null )
9690 {
97- result = "No Upload: all selected rows are already uploaded!" ;
98- }
99- else
100- {
101- //get duplicated ids for result text
102- var dups = rowIds . Except ( noDuplicateIds ) ;
103- result += "Duplicated ids not uploaded: <br>" ;
104- foreach ( int d in dups )
105- {
106- result += d . ToString ( ) + "<br>" ;
107- }
91+ ComponentDataModel compData = Session [ "ComponentData" ] as ComponentDataModel ;
10892
109- DataApiModel model = new DataApiModel ( ) ;
110- model . DatasetId = Convert . ToInt64 ( Models . Settings . get ( "lui:datasetNewComponentsSet" ) ) ;
111- model . DecimalCharacter = DecimalCharacter . point ;
93+ //check for dublicates
94+ int [ ] duplicateIds = CheckDuplicates ( compData . Data , rowIds ) ;
11295
113- //get col names
114- List < string > cols = new List < string > ( ) ;
115- foreach ( DataColumn colum in compData . Data . Columns )
96+ if ( duplicateIds . Length == rowIds . Length )
11697 {
117- if ( colum . ColumnName != "Id" )
118- cols . Add ( colum . ColumnName ) ;
98+ result = "No Upload: all selected rows are already uploaded!" ;
11999 }
100+ else
101+ {
102+ //get duplicated ids for result text
103+ //var dups = rowIds.Except(noDuplicateIds);
104+ if ( duplicateIds . Length > 0 )
105+ {
106+ result += "Duplicated ids not uploaded: " ;
107+ foreach ( int d in duplicateIds )
108+ {
109+ if ( duplicateIds . Last ( ) == d )
110+ result += d . ToString ( ) + " " ;
111+ else
112+ result += d . ToString ( ) + ", " ;
113+ }
114+
115+ result += "<br/>" ;
116+ }
120117
121- model . Columns = cols . ToArray ( ) ;
122118
123- string [ , ] dataArray = new string [ rowIds . Count ( ) , cols . Count ] ;
119+ DataApiModel model = new DataApiModel ( ) ;
120+ model . DatasetId = Convert . ToInt64 ( Models . Settings . get ( "lui:datasetNewComponentsSet" ) ) ;
121+ model . DecimalCharacter = DecimalCharacter . point ;
124122
125- List < string [ ] > dataArrays = new List < string [ ] > ( ) ;
126- if ( rowIds != null )
127- {
128- foreach ( int id in noDuplicateIds )
123+ //get col names
124+ List < string > cols = new List < string > ( ) ;
125+ foreach ( DataColumn colum in compData . Data . Columns )
129126 {
130- DataTable copy = new DataTable ( ) ;
131- copy = compData . Data . Copy ( ) ;
127+ if ( colum . ColumnName != "Id" )
128+ cols . Add ( colum . ColumnName ) ;
129+ }
132130
133- DataRow row = copy . AsEnumerable ( ) . Where ( a => a . Field < int > ( "Id" ) == id ) . FirstOrDefault ( ) ;
134- row . Table . Columns . Remove ( "Id" ) ;
131+ model . Columns = cols . ToArray ( ) ;
135132
136- string [ ] stringArray = row . ItemArray . Cast < string > ( ) . ToArray ( ) ;
137- dataArrays . Add ( stringArray ) ;
138- }
133+ string [ , ] dataArray = new string [ rowIds . Count ( ) , cols . Count ] ;
139134
140- model . Data = dataArrays . ToArray ( ) ;
141- }
135+ List < string [ ] > dataArrays = new List < string [ ] > ( ) ;
136+
137+ //get all not duplicated id
138+ var idsToUpload = rowIds . Except ( duplicateIds ) ;
139+ if ( idsToUpload . Count ( ) > 0 )
140+ result += "Uploaded Ids: " ;
141+
142+ foreach ( int id in idsToUpload )
143+ {
144+ DataTable copy = new DataTable ( ) ;
145+ copy = compData . Data . Copy ( ) ;
146+
147+ DataRow row = copy . AsEnumerable ( ) . Where ( a => a . Field < int > ( "Id" ) == id ) . FirstOrDefault ( ) ;
148+ row . Table . Columns . Remove ( "Id" ) ;
149+
150+ string [ ] stringArray = row . ItemArray . Cast < string > ( ) . ToArray ( ) ;
151+ dataArrays . Add ( stringArray ) ;
152+
153+ if ( idsToUpload . Last ( ) == id )
154+ result += id . ToString ( ) + " " ;
155+ else
156+ result += id . ToString ( ) + ", " ;
157+ }
158+ result += "<br/>" ;
142159
143- //upload
144- result = DataAccess . Upload ( model , GetServerInformation ( ) ) ;
160+ model . Data = dataArrays . ToArray ( ) ;
161+
162+ //upload
163+ result += "API response: " + DataAccess . Upload ( model , GetServerInformation ( ) ) + "<br/>" ;
164+
165+ }
166+ }
167+ else
168+ {
169+ result += "No Upload: no rows selected." ;
145170 }
146171
147172 return Content ( result ) ;
@@ -193,17 +218,19 @@ private int[] CheckDuplicates(DataTable newCompData, int[] rowIds)
193218 string luiIdNew = Models . Settings . get ( "lui:datasetNewComponentsSet" ) . ToString ( ) ;
194219 DataTable allCompData = DataAccess . GetComponentData ( luiIdNew , GetServerInformation ( ) ) ;
195220
196- List < int > noDuplicates = new List < int > ( ) ;
221+ List < int > duplicates = new List < int > ( ) ;
197222 foreach ( int id in rowIds )
198223 {
199224 var row = newCompData . AsEnumerable ( ) . Where ( a => a . Field < int > ( "Id" ) == id ) . FirstOrDefault ( ) ;
200- var duplicate = allCompData . AsEnumerable ( ) . Where ( c=> c . Field < string > ( "EP_PlotID" ) == row . Field < string > ( "EP_PlotID" ) && c . Field < DateTime > ( "Year" ) . ToString ( "yyyy" ) == row . Field < string > ( "Year" ) ) . First ( ) ;
201- if ( duplicate == null )
202- noDuplicates . Add ( id ) ;
225+ var duplicate = allCompData . AsEnumerable ( ) . Where ( c=> c . Field < string > ( "EP_PlotID" ) == row . Field < string > ( "EP_PlotID" ) && c . Field < DateTime > ( "Year" ) . ToString ( "yyyy" ) == row . Field < string > ( 1 ) ) . FirstOrDefault ( ) ;
226+ if ( duplicate != null )
227+ duplicates . Add ( id ) ;
228+
229+
203230
204231 }
205232
206- return noDuplicates . ToArray ( ) ;
233+ return duplicates . ToArray ( ) ;
207234 }
208235 }
209236}
0 commit comments