Commit 63c7611cd9fdd929b64d8d43dbe543b70be3fd15
1 parent
24282405
working code for sql to json conversion.
Showing
1 changed file
with
53 additions
and
38 deletions
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs
... | ... | @@ -99,86 +99,101 @@ namespace SQLToJSON |
99 | 99 | |
100 | 100 | data2 = data.ToList(); |
101 | 101 | string previousUserId =""; |
102 | + string previousUserType=""; | |
102 | 103 | |
103 | 104 | string modId=null; |
104 | 105 | string modName = null; |
105 | 106 | string modSlug = null; |
107 | + | |
106 | 108 | foreach (var row in data) |
107 | 109 | { |
108 | 110 | string userloginId = row.loginId; |
109 | 111 | if (userloginId != previousUserId) |
110 | 112 | { |
111 | 113 | List<UserModules> userMods = new List<UserModules>(); |
114 | + List<string> userTypes = new List<string>(); | |
112 | 115 | |
113 | 116 | previousUserId = userloginId; |
114 | 117 | |
118 | + | |
119 | + string userT = row.UserType; | |
120 | + if (previousUserType != userT) | |
121 | + { | |
122 | + userTypes.Add(userT); | |
123 | + previousUserType = userT; | |
124 | + | |
125 | + } | |
126 | + | |
115 | 127 | var Modules = (from m in data |
116 | 128 | where m.loginId == userloginId |
117 | 129 | select m.module).ToList(); |
118 | - | |
119 | - | |
130 | + | |
120 | 131 | |
121 | 132 | foreach (var mods in Modules) |
122 | 133 | { |
123 | 134 | string MO = mods.ToString().Replace(@"\", ""); |
124 | - // modId = moduleIds[mods]; | |
125 | 135 | if (MO == "CAM") |
126 | 136 | { |
127 | - // modul.name = "Complementary and Alternative Medicine"; | |
128 | 137 | modName = "Complementary and Alternative Medicine"; |
129 | 138 | } |
130 | 139 | else if (MO == "Anatomy Test") |
131 | 140 | { |
132 | - // modul.name = "Anatomy Tests"; | |
133 | 141 | modName = "Anatomy Tests"; |
134 | 142 | |
135 | 143 | } |
136 | 144 | else |
137 | 145 | { |
138 | - // modul.name = mods; | |
139 | 146 | modName= mods; |
140 | 147 | } |
141 | - // modul.slug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")]; | |
142 | 148 | modSlug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")]; |
143 | 149 | userMods.Add(new UserModules { id = moduleIds[mods], name = modName, slug = modSlug }); |
144 | - | |
145 | - // var lst2 = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = (JsonConvert.SerializeObject(userMods)); return r; }).ToList(); | |
146 | - | |
147 | - // mo.modules.Add(modul); | |
150 | + | |
148 | 151 | |
149 | 152 | } |
150 | 153 | |
151 | 154 | previousUserId = userloginId; |
152 | 155 | |
153 | - | |
154 | 156 | |
155 | - // var lst = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = (mo).ToString(); return r; }).ToList(); | |
156 | - // string moddd = ((from mod in lst | |
157 | - // select mod.module).FirstOrDefault().ToString()).Replace(@"\", ""); | |
158 | - // string abc = Regex.Unescape(moddd); | |
157 | + var lst2 = data2.Where(w => w.loginId == userloginId).Select(r => new User | |
158 | + { | |
159 | + loginId = row.loginId, | |
160 | + password = row.password, | |
161 | + firstName = row.firstName, | |
162 | + lastName = row.lastName, | |
163 | + UserType = row.UserType, | |
164 | + emailId = row.emailId, | |
165 | + isActive = row.isActive, | |
166 | + securityQuestion = row.securityQuestion, | |
167 | + securityAnswer = row.securityAnswer, | |
168 | + creatorId = row.creatorId, | |
169 | + creationDate = row.creationDate, | |
170 | + modifierId = row.modifierId, | |
171 | + modifiedDate = row.modifiedDate, | |
172 | + deactivationDate = row.deactivationDate, | |
173 | + modules = userMods, | |
174 | + userType = userTypes | |
175 | + }).ToList(); | |
176 | + | |
159 | 177 | |
160 | - var lst2 = data2.Where(w => w.loginId == userloginId).Select(r =>new User{ loginId = row.loginId, | |
161 | - password =row.password, | |
162 | - firstName = row.firstName, | |
163 | - lastName = row.lastName, | |
164 | - UserType = row.UserType, | |
165 | - emailId = row.emailId, | |
166 | - isActive = row.isActive, | |
167 | - securityQuestion = row.securityQuestion, | |
168 | - securityAnswer = row.securityAnswer, | |
169 | - creatorId = row.creatorId, | |
170 | - creationDate = row.creationDate, | |
171 | - modifierId = row.modifierId, | |
172 | - modifiedDate = row.modifiedDate, | |
173 | - deactivationDate = row.deactivationDate,modules = userMods}).ToList(); | |
174 | - | |
175 | - var reultantRow = lst2.FirstOrDefault(); | |
176 | - // //to create array of userType | |
177 | - List<string> userTypes = new List<string>(); | |
178 | - var userType1 = (reultantRow.UserType); | |
179 | - userTypes.Add(userType1); | |
180 | - ////userTypes.Add("Admin"); | |
181 | - reultantRow.userType =userTypes; | |
178 | + | |
179 | + var reultantRow = lst2.Take(1).Select(a=>new{ | |
180 | + loginId = a.loginId, | |
181 | + password = a.password, | |
182 | + firstName = a.firstName, | |
183 | + lastName = a.lastName, | |
184 | + userType = a.userType, | |
185 | + emailId = a.emailId, | |
186 | + isActive = a.isActive, | |
187 | + securityQuestion = a.securityQuestion, | |
188 | + securityAnswer = a.securityAnswer, | |
189 | + creatorId = a.creatorId, | |
190 | + creationDate = a.creationDate, | |
191 | + modifierId = a.modifierId, | |
192 | + modifiedDate = a.modifiedDate, | |
193 | + deactivationDate = a.deactivationDate, | |
194 | + modules = a.modules | |
195 | + }).ToList(); | |
196 | + | |
182 | 197 | RESULT.Add(reultantRow); |
183 | 198 | } |
184 | 199 | } | ... | ... |