diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs index 4de0313..c791281 100644 --- a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs @@ -82,7 +82,7 @@ namespace SQLToJSON password = d.Field("password"), firstName = d.Field("firstName"), lastName = d.Field("lastName"), - userType = d.Field("userType"), + UserType = d.Field("userType"), emailId = d.Field("emailId"), isActive = d.Field("isActive"), securityQuestion = d.Field("securityQuestion"), @@ -99,6 +99,10 @@ namespace SQLToJSON data2 = data.ToList(); string previousUserId =""; + List userMods = new List(); + string modId=null; + string modName = null; + string modSlug = null; foreach (var row in data) { @@ -122,20 +126,26 @@ namespace SQLToJSON dynamic modul = new JObject(); string MO = mods.ToString().Replace(@"\", ""); modul.id = moduleIds[mods]; + 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(@"\", "")]; + new UserModules { id = moduleIds[mods], name = modName, slug = modSlug }; mo.modules.Add(modul); } @@ -153,10 +163,10 @@ namespace SQLToJSON var reultantRow = lst2.FirstOrDefault(); //to create array of userType List userTypes = new List(); - var userType1 = (reultantRow.userType); + var userType1 = (reultantRow.UserType); userTypes.Add(userType1); //userTypes.Add("Admin"); - reultantRow.userType = JsonConvert.SerializeObject(userTypes); + reultantRow.userType = userTypes; RESULT.Add(reultantRow); } } diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs new file mode 100644 index 0000000..debb699 --- /dev/null +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Configuration; +using System.Data.SqlClient; +using System.Configuration; +using Newtonsoft.Json.Linq; +using System.Text.RegularExpressions; +using System.Web; + +namespace SQLToJSON +{ + class DataAccess + { + string connString = string.Empty; + public DataAccess() + { + connString = Convert.ToString(ConfigurationManager.AppSettings["connectionString"]); + } + + public DataTable FetchDataFromTable(string cmd) + { + DataTable resultTable; + SqlDataAdapter da = new SqlDataAdapter(cmd, connString); + DataSet ds = new DataSet(); + da.Fill(ds); + resultTable = ds.Tables[0]; + return resultTable; + } + //nbh + public string DataTableToJSONWithJSONNet(dynamic table) + { + string JSONString = string.Empty; + JSONString = JsonConvert.SerializeObject(table); + string replacedString = JSONString.Replace(@"\r", ""); + string replacedString1 = replacedString.Replace(@"\n", ""); + string replacedString2 = replacedString1.Replace(@"\", ""); + + string finalString = Regex.Replace(replacedString2, "\\s+\"", ""); + + return finalString; + } + + public dynamic GetModifiedTableWithUserModules(DataTable userTable, DataTable moduleTable) + { + List data2 = null; + List RESULT = new List(); + try + { + Dictionary moduleIds = new Dictionary(); + moduleIds.Add("Dissectible Anatomy", "1"); + moduleIds.Add("Atlas Anatomy", "2"); + moduleIds.Add("3D Anatomy", "3"); + moduleIds.Add("Clinical Illustrations", "4"); + moduleIds.Add("Clinical Animations", "5"); + moduleIds.Add("Encyclopedia", "6"); + moduleIds.Add("Curriculum Builder", "7"); + moduleIds.Add("Anatomy Test", "8"); + moduleIds.Add("IP 10", "9"); + moduleIds.Add("Lab Exercises", "10"); + moduleIds.Add("In-Depth Reports", "11"); + moduleIds.Add("CAM", "12"); + moduleIds.Add("A.D.A.M. Images", "13"); + moduleIds.Add("Body Guide", "14"); + moduleIds.Add("Symptom Navigator", "15"); + moduleIds.Add("The Wellness Tools", "16"); + moduleIds.Add("A.D.A.M. OnDemand", "1017"); + // moduleIds.Add("Dissectible Anatomy", "1"); + + + List data = (from d in userTable.AsEnumerable() + join e in moduleTable.AsEnumerable() + on d.Field("Id") equals + e.Field("UserId") + select new User + { + loginId = d.Field("loginId"), + password = d.Field("password"), + firstName = d.Field("firstName"), + lastName = d.Field("lastName"), + UserType = d.Field("userType"), + emailId = d.Field("emailId"), + isActive = d.Field("isActive"), + securityQuestion = d.Field("securityQuestion"), + securityAnswer = d.Field("securityAnswer"), + creatorId = d.Field("creatorId"), + creationDate = d.Field("creationDate"), + modifierId = d.Field("modifierId"), + modifiedDate = d.Field("modifiedDate"), + deactivationDate = d.Field("deactivationDate"), + module = e.Field("Title"), + //JsonConvert.SerializeObject(e.Field("Title")), + }).ToList(); + + + data2 = data.ToList(); + string previousUserId =""; + + 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(); + + previousUserId = userloginId; + + 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}).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; + RESULT.Add(reultantRow); + } + } + + return RESULT; + } + catch (Exception e) + { + return e.Message; + } + + } + } +} diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs index c5ece98..7e6cf89 100644 --- a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs @@ -14,11 +14,11 @@ namespace SQLToJSON { public partial class Form1 : Form { - Custom objClass; + DataAccess objClass; public Form1() { InitializeComponent(); - objClass = new Custom(); + objClass = new DataAccess(); } private void button1_Click(object sender, EventArgs e) diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Modules.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Modules.cs new file mode 100644 index 0000000..d932ce8 --- /dev/null +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Modules.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SQLToJSON +{ + public class UseModules + { + + public string id { get; set; } + public string name { get; set; } + public string slug { get; set; } + } +} diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/SQLToJSON.csproj b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/SQLToJSON.csproj index 102538c..ee1ffdf 100644 --- a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/SQLToJSON.csproj +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/SQLToJSON.csproj @@ -51,17 +51,20 @@ + Form Form1.cs + + Form1.cs diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/User.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/User.cs index bc339db..b660480 100644 --- a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/User.cs +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/User.cs @@ -13,7 +13,7 @@ namespace SQLToJSON public string password { get; set; } public string firstName { get; set; } public string lastName { get; set; } - public string userType { get; set; } + public string UserType { get; set; } public string emailId { get; set; } public bool isActive { get; set; } public string securityQuestion { get; set; } @@ -23,7 +23,9 @@ namespace SQLToJSON public int modifierId { get; set; } public DateTime? modifiedDate { get; set; } public DateTime? deactivationDate { get; set; } - public string module { get; set; } - + public string module { get; set; } + public List modules { get; set; } + public List userType { get; set; } + } } diff --git a/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/UserModules.cs b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/UserModules.cs new file mode 100644 index 0000000..e408805 --- /dev/null +++ b/350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/UserModules.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SQLToJSON +{ + public class UserModules + { + + public string id { get; set; } + public string name { get; set; } + public string slug { get; set; } + + } +}