@@ -46,9 +46,21 @@ public ActionResult Index()
4646 // set page title
4747 ViewBag . Title = PresentationModel . GetViewTitleForTenant ( TITLE , this . Session . GetTenant ( ) ) ;
4848
49+
4950 //create model
5051 LUIQueryModel model = new LUIQueryModel ( ) ;
5152 model . MissingComponentData = DataAccess . GetMissingComponentData ( GetServerInformation ( ) ) ;
53+
54+ //check if public access
55+ long . TryParse ( this . User . Identity . GetUserId ( ) , out long userId ) ;
56+
57+ //no bexis user == public access and id uncomplete data exsits
58+ if ( userId == 0 && model . MissingComponentData . Count ( ) > 0 )
59+ {
60+ model . IsPublicAccess = true ;
61+ }
62+
63+
5264 model . NewComponentsSetDatasetId = Models . Settings . get ( "lui:datasetNewComponentsSet" ) . ToString ( ) ;
5365 var datasetInfo = DataAccess . GetDatasetInfo ( model . NewComponentsSetDatasetId , GetServerInformation ( ) ) ;
5466 model . NewComponentsSetDatasetVersion = DataAccess . GetDatasetInfo ( model . NewComponentsSetDatasetId , GetServerInformation ( ) ) . Version ;
@@ -66,15 +78,31 @@ public ActionResult Index()
6678 }
6779 }
6880
69- public ActionResult ShowPrimaryData ( long datasetID )
81+ public ActionResult ShowPrimaryData ( long datasetID , bool isPublicAccess )
7082 {
7183 LUIQueryModel lUIQueryModel = new LUIQueryModel ( ) ;
7284 lUIQueryModel . RawVsCalc . SelectedValue = "unstandardized" ;
7385 lUIQueryModel . DownloadDatasetId = datasetID . ToString ( ) ;
7486 Session [ "LUICalModel" ] = lUIQueryModel ;
7587
7688 DataModel model = new DataModel ( ) ;
77- model . Data = DataAccess . GetComponentData ( datasetID . ToString ( ) , GetServerInformation ( ) ) ;
89+ DataTable data = DataAccess . GetComponentData ( datasetID . ToString ( ) , GetServerInformation ( ) ) ;
90+ if ( isPublicAccess )
91+ {
92+ //remove not complete years data for non public access
93+ var missingData = DataAccess . GetMissingComponentData ( GetServerInformation ( ) ) ;
94+ if ( missingData . Count > 0 )
95+ {
96+ List < string > incompleteYears = missingData . Select ( x => x . Year ) . Distinct ( ) . ToList ( ) ;
97+ RemoveNotComplateYears ( data , incompleteYears ) ;
98+ model . Data = data ;
99+
100+ }
101+ else
102+ model . Data = data ;
103+ }
104+ else
105+ model . Data = data ;
78106
79107 return PartialView ( "_data" , model ) ;
80108 }
@@ -122,6 +150,18 @@ public ActionResult CalculateLUI(LUIQueryModel model)
122150 break ;
123151 }
124152 DataTable dt_sourceData = DataAccess . GetComponentData ( dsId , GetServerInformation ( ) ) ;
153+ if ( model . IsPublicAccess )
154+ {
155+ //remove not complete years data for non public access
156+ var missingData = DataAccess . GetMissingComponentData ( GetServerInformation ( ) ) ;
157+ if ( missingData . Count > 0 )
158+ {
159+ List < string > incompleteYears = missingData . Select ( x => x . Year ) . Distinct ( ) . ToList ( ) ;
160+ RemoveNotComplateYears ( dt_sourceData , incompleteYears ) ;
161+ }
162+
163+ }
164+
125165 var results = CalculateLui . DoCalc ( model , dt_sourceData ) ;
126166
127167 DataModel dataModel = new DataModel ( ) ;
@@ -361,6 +401,9 @@ private string GetUserToken()
361401 long userId = 0 ;
362402 long . TryParse ( this . User . Identity . GetUserId ( ) , out userId ) ;
363403
404+ if ( userId == 0 )
405+ return "" ;
406+
364407 var user = identityUserService . FindById ( userId ) ;
365408
366409 user = identityUserService . FindById ( userId ) ;
@@ -373,6 +416,15 @@ private string GetUserToken()
373416 userManager . Dispose ( ) ;
374417 }
375418 }
419+
420+ private void RemoveNotComplateYears ( DataTable data , List < string > years )
421+ {
422+ foreach ( var year in years )
423+ {
424+ data . AsEnumerable ( ) . Where ( r => r . Field < DateTime > ( "Year" ) . ToString ( "yyyy" ) == year ) . ToList ( ) . ForEach ( row => row . Delete ( ) ) ;
425+ data . AcceptChanges ( ) ;
426+ }
427+ }
376428 }
377429
378430}
0 commit comments