diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs index debb699..a773c1c 100644 --- a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs @@ -99,86 +99,101 @@ namespace SQLToJSON data2 = data.ToList(); string previousUserId =""; + string previousUserType=""; string modId=null; string modName = null; string modSlug = null; + foreach (var row in data) { string userloginId = row.loginId; if (userloginId != previousUserId) { List userMods = new List(); + List userTypes = new List(); previousUserId = userloginId; + + string userT = row.UserType; + if (previousUserType != userT) + { + userTypes.Add(userT); + previousUserType = userT; + + } + var Modules = (from m in data where m.loginId == userloginId select m.module).ToList(); - - + foreach (var mods in Modules) { string MO = mods.ToString().Replace(@"\", ""); - // modId = moduleIds[mods]; if (MO == "CAM") { - // modul.name = "Complementary and Alternative Medicine"; modName = "Complementary and Alternative Medicine"; } else if (MO == "Anatomy Test") { - // modul.name = "Anatomy Tests"; modName = "Anatomy Tests"; } else { - // modul.name = mods; modName= mods; } - // modul.slug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")]; modSlug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")]; userMods.Add(new UserModules { id = moduleIds[mods], name = modName, slug = modSlug }); - - // var lst2 = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = (JsonConvert.SerializeObject(userMods)); return r; }).ToList(); - - // mo.modules.Add(modul); + } previousUserId = userloginId; - - // var lst = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = (mo).ToString(); return r; }).ToList(); - // string moddd = ((from mod in lst - // select mod.module).FirstOrDefault().ToString()).Replace(@"\", ""); - // string abc = Regex.Unescape(moddd); + var lst2 = data2.Where(w => w.loginId == userloginId).Select(r => new User + { + loginId = row.loginId, + password = row.password, + firstName = row.firstName, + lastName = row.lastName, + UserType = row.UserType, + emailId = row.emailId, + isActive = row.isActive, + securityQuestion = row.securityQuestion, + securityAnswer = row.securityAnswer, + creatorId = row.creatorId, + creationDate = row.creationDate, + modifierId = row.modifierId, + modifiedDate = row.modifiedDate, + deactivationDate = row.deactivationDate, + modules = userMods, + userType = userTypes + }).ToList(); + - var lst2 = data2.Where(w => w.loginId == userloginId).Select(r =>new User{ loginId = row.loginId, - password =row.password, - firstName = row.firstName, - lastName = row.lastName, - UserType = row.UserType, - emailId = row.emailId, - isActive = row.isActive, - securityQuestion = row.securityQuestion, - securityAnswer = row.securityAnswer, - creatorId = row.creatorId, - creationDate = row.creationDate, - modifierId = row.modifierId, - modifiedDate = row.modifiedDate, - deactivationDate = row.deactivationDate,modules = userMods}).ToList(); - - var reultantRow = lst2.FirstOrDefault(); - // //to create array of userType - List userTypes = new List(); - var userType1 = (reultantRow.UserType); - userTypes.Add(userType1); - ////userTypes.Add("Admin"); - reultantRow.userType =userTypes; + + var reultantRow = lst2.Take(1).Select(a=>new{ + loginId = a.loginId, + password = a.password, + firstName = a.firstName, + lastName = a.lastName, + userType = a.userType, + emailId = a.emailId, + isActive = a.isActive, + securityQuestion = a.securityQuestion, + securityAnswer = a.securityAnswer, + creatorId = a.creatorId, + creationDate = a.creationDate, + modifierId = a.modifierId, + modifiedDate = a.modifiedDate, + deactivationDate = a.deactivationDate, + modules = a.modules + }).ToList(); + RESULT.Add(reultantRow); } }