Commit 242824056e35d0b51f601e1fc546dc38dc597a9d

Authored by Nikita Kulshreshtha
1 parent 3aef1e2b

chnaged implementation due to inavlid json. now using list for modules and usertype.

after converting data into json, need to validate it.
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs
... ... @@ -82,7 +82,7 @@ namespace SQLToJSON
82 82 password = d.Field<string>("password"),
83 83 firstName = d.Field<string>("firstName"),
84 84 lastName = d.Field<string>("lastName"),
85   - userType = d.Field<string>("userType"),
  85 + UserType = d.Field<string>("userType"),
86 86 emailId = d.Field<string>("emailId"),
87 87 isActive = d.Field<Boolean>("isActive"),
88 88 securityQuestion = d.Field<string>("securityQuestion"),
... ... @@ -99,6 +99,10 @@ namespace SQLToJSON
99 99  
100 100 data2 = data.ToList();
101 101 string previousUserId ="";
  102 + List<UserModules> userMods = new List<UserModules>();
  103 + string modId=null;
  104 + string modName = null;
  105 + string modSlug = null;
102 106 foreach (var row in data)
103 107 {
104 108  
... ... @@ -122,20 +126,26 @@ namespace SQLToJSON
122 126 dynamic modul = new JObject();
123 127 string MO = mods.ToString().Replace(@"\", "");
124 128 modul.id = moduleIds[mods];
  129 + modId = moduleIds[mods];
125 130 if (MO == "CAM")
126 131 {
127 132 modul.name = "Complementary and Alternative Medicine";
  133 + modName = "Complementary and Alternative Medicine";
128 134 }
129 135 else if (MO == "Anatomy Test")
130 136 {
131 137 modul.name = "Anatomy Tests";
  138 + modName = "Anatomy Tests";
132 139  
133 140 }
134 141 else
135 142 {
136 143 modul.name = mods;
  144 + modName= mods;
137 145 }
138 146 modul.slug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")];
  147 + modSlug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")];
  148 + new UserModules { id = moduleIds[mods], name = modName, slug = modSlug };
139 149 mo.modules.Add(modul);
140 150  
141 151 }
... ... @@ -153,10 +163,10 @@ namespace SQLToJSON
153 163 var reultantRow = lst2.FirstOrDefault();
154 164 //to create array of userType
155 165 List<string> userTypes = new List<string>();
156   - var userType1 = (reultantRow.userType);
  166 + var userType1 = (reultantRow.UserType);
157 167 userTypes.Add(userType1);
158 168 //userTypes.Add("Admin");
159   - reultantRow.userType = JsonConvert.SerializeObject(userTypes);
  169 + reultantRow.userType = userTypes;
160 170 RESULT.Add(reultantRow);
161 171 }
162 172 }
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/DataAccess.cs 0 → 100644
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Data;
  4 +using System.Linq;
  5 +using System.Text;
  6 +using System.Threading.Tasks;
  7 +using Newtonsoft.Json;
  8 +using System.Configuration;
  9 +using System.Data.SqlClient;
  10 +using System.Configuration;
  11 +using Newtonsoft.Json.Linq;
  12 +using System.Text.RegularExpressions;
  13 +using System.Web;
  14 +
  15 +namespace SQLToJSON
  16 +{
  17 + class DataAccess
  18 + {
  19 + string connString = string.Empty;
  20 + public DataAccess()
  21 + {
  22 + connString = Convert.ToString(ConfigurationManager.AppSettings["connectionString"]);
  23 + }
  24 +
  25 + public DataTable FetchDataFromTable(string cmd)
  26 + {
  27 + DataTable resultTable;
  28 + SqlDataAdapter da = new SqlDataAdapter(cmd, connString);
  29 + DataSet ds = new DataSet();
  30 + da.Fill(ds);
  31 + resultTable = ds.Tables[0];
  32 + return resultTable;
  33 + }
  34 + //nbh
  35 + public string DataTableToJSONWithJSONNet(dynamic table)
  36 + {
  37 + string JSONString = string.Empty;
  38 + JSONString = JsonConvert.SerializeObject(table);
  39 + string replacedString = JSONString.Replace(@"\r", "");
  40 + string replacedString1 = replacedString.Replace(@"\n", "");
  41 + string replacedString2 = replacedString1.Replace(@"\", "");
  42 +
  43 + string finalString = Regex.Replace(replacedString2, "\\s+\"", "");
  44 +
  45 + return finalString;
  46 + }
  47 +
  48 + public dynamic GetModifiedTableWithUserModules(DataTable userTable, DataTable moduleTable)
  49 + {
  50 + List<User> data2 = null;
  51 + List<dynamic> RESULT = new List<dynamic>();
  52 + try
  53 + {
  54 + Dictionary<string,string> moduleIds = new Dictionary<string,string>();
  55 + moduleIds.Add("Dissectible Anatomy", "1");
  56 + moduleIds.Add("Atlas Anatomy", "2");
  57 + moduleIds.Add("3D Anatomy", "3");
  58 + moduleIds.Add("Clinical Illustrations", "4");
  59 + moduleIds.Add("Clinical Animations", "5");
  60 + moduleIds.Add("Encyclopedia", "6");
  61 + moduleIds.Add("Curriculum Builder", "7");
  62 + moduleIds.Add("Anatomy Test", "8");
  63 + moduleIds.Add("IP 10", "9");
  64 + moduleIds.Add("Lab Exercises", "10");
  65 + moduleIds.Add("In-Depth Reports", "11");
  66 + moduleIds.Add("CAM", "12");
  67 + moduleIds.Add("A.D.A.M. Images", "13");
  68 + moduleIds.Add("Body Guide", "14");
  69 + moduleIds.Add("Symptom Navigator", "15");
  70 + moduleIds.Add("The Wellness Tools", "16");
  71 + moduleIds.Add("A.D.A.M. OnDemand", "1017");
  72 + // moduleIds.Add("Dissectible Anatomy", "1");
  73 +
  74 +
  75 + List<User> data = (from d in userTable.AsEnumerable()
  76 + join e in moduleTable.AsEnumerable()
  77 + on d.Field<int>("Id") equals
  78 + e.Field<int>("UserId")
  79 + select new User
  80 + {
  81 + loginId = d.Field<string>("loginId"),
  82 + password = d.Field<string>("password"),
  83 + firstName = d.Field<string>("firstName"),
  84 + lastName = d.Field<string>("lastName"),
  85 + UserType = d.Field<string>("userType"),
  86 + emailId = d.Field<string>("emailId"),
  87 + isActive = d.Field<Boolean>("isActive"),
  88 + securityQuestion = d.Field<string>("securityQuestion"),
  89 + securityAnswer = d.Field<string>("securityAnswer"),
  90 + creatorId = d.Field<int>("creatorId"),
  91 + creationDate = d.Field<DateTime?>("creationDate"),
  92 + modifierId = d.Field<int>("modifierId"),
  93 + modifiedDate = d.Field<DateTime?>("modifiedDate"),
  94 + deactivationDate = d.Field<DateTime?>("deactivationDate"),
  95 + module = e.Field<string>("Title"),
  96 + //JsonConvert.SerializeObject(e.Field<string>("Title")),
  97 + }).ToList();
  98 +
  99 +
  100 + data2 = data.ToList();
  101 + string previousUserId ="";
  102 +
  103 + string modId=null;
  104 + string modName = null;
  105 + string modSlug = null;
  106 + foreach (var row in data)
  107 + {
  108 + string userloginId = row.loginId;
  109 + if (userloginId != previousUserId)
  110 + {
  111 + List<UserModules> userMods = new List<UserModules>();
  112 +
  113 + previousUserId = userloginId;
  114 +
  115 + var Modules = (from m in data
  116 + where m.loginId == userloginId
  117 + select m.module).ToList();
  118 +
  119 +
  120 +
  121 + foreach (var mods in Modules)
  122 + {
  123 + string MO = mods.ToString().Replace(@"\", "");
  124 + // modId = moduleIds[mods];
  125 + if (MO == "CAM")
  126 + {
  127 + // modul.name = "Complementary and Alternative Medicine";
  128 + modName = "Complementary and Alternative Medicine";
  129 + }
  130 + else if (MO == "Anatomy Test")
  131 + {
  132 + // modul.name = "Anatomy Tests";
  133 + modName = "Anatomy Tests";
  134 +
  135 + }
  136 + else
  137 + {
  138 + // modul.name = mods;
  139 + modName= mods;
  140 + }
  141 + // modul.slug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")];
  142 + modSlug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")];
  143 + 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);
  148 +
  149 + }
  150 +
  151 + previousUserId = userloginId;
  152 +
  153 +
  154 +
  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);
  159 +
  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;
  182 + RESULT.Add(reultantRow);
  183 + }
  184 + }
  185 +
  186 + return RESULT;
  187 + }
  188 + catch (Exception e)
  189 + {
  190 + return e.Message;
  191 + }
  192 +
  193 + }
  194 + }
  195 +}
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs
... ... @@ -14,11 +14,11 @@ namespace SQLToJSON
14 14 {
15 15 public partial class Form1 : Form
16 16 {
17   - Custom objClass;
  17 + DataAccess objClass;
18 18 public Form1()
19 19 {
20 20 InitializeComponent();
21   - objClass = new Custom();
  21 + objClass = new DataAccess();
22 22 }
23 23  
24 24 private void button1_Click(object sender, EventArgs e)
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Modules.cs 0 → 100644
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Text;
  5 +using System.Threading.Tasks;
  6 +
  7 +namespace SQLToJSON
  8 +{
  9 + public class UseModules
  10 + {
  11 +
  12 + public string id { get; set; }
  13 + public string name { get; set; }
  14 + public string slug { get; set; }
  15 + }
  16 +}
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/SQLToJSON.csproj
... ... @@ -51,17 +51,20 @@
51 51 </ItemGroup>
52 52 <ItemGroup>
53 53 <Compile Include="Custom.cs" />
  54 + <Compile Include="DataAccess.cs" />
54 55 <Compile Include="Form1.cs">
55 56 <SubType>Form</SubType>
56 57 </Compile>
57 58 <Compile Include="Form1.Designer.cs">
58 59 <DependentUpon>Form1.cs</DependentUpon>
59 60 </Compile>
  61 + <Compile Include="Modules.cs" />
60 62 <Compile Include="Program.cs" />
61 63 <Compile Include="Properties\AssemblyInfo.cs" />
62 64 <Compile Include="StringContent.cs" />
63 65 <Compile Include="StringContent_2.cs" />
64 66 <Compile Include="User.cs" />
  67 + <Compile Include="UserModules.cs" />
65 68 <EmbeddedResource Include="Form1.resx">
66 69 <DependentUpon>Form1.cs</DependentUpon>
67 70 </EmbeddedResource>
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/User.cs
... ... @@ -13,7 +13,7 @@ namespace SQLToJSON
13 13 public string password { get; set; }
14 14 public string firstName { get; set; }
15 15 public string lastName { get; set; }
16   - public string userType { get; set; }
  16 + public string UserType { get; set; }
17 17 public string emailId { get; set; }
18 18 public bool isActive { get; set; }
19 19 public string securityQuestion { get; set; }
... ... @@ -23,7 +23,9 @@ namespace SQLToJSON
23 23 public int modifierId { get; set; }
24 24 public DateTime? modifiedDate { get; set; }
25 25 public DateTime? deactivationDate { get; set; }
26   - public string module { get; set; }
27   -
  26 + public string module { get; set; }
  27 + public List<UserModules> modules { get; set; }
  28 + public List<string> userType { get; set; }
  29 +
28 30 }
29 31 }
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/UserModules.cs 0 → 100644
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Text;
  5 +using System.Threading.Tasks;
  6 +
  7 +namespace SQLToJSON
  8 +{
  9 + public class UserModules
  10 + {
  11 +
  12 + public string id { get; set; }
  13 + public string name { get; set; }
  14 + public string slug { get; set; }
  15 +
  16 + }
  17 +}
... ...