public string UserLogin(string username, string password) { //return msg data initialization DataSet ds = new DataSet(); DataTable loginMsg = new DataTable(); loginMsg.Columns.Add("Flag", typeof(Boolean)); loginMsg.Columns.Add("Message", typeof(String)); DataRow dr = loginMsg.NewRow(); ClinicDAL.CryptographyFunctions crypto = new ClinicDAL.CryptographyFunctions(); username = crypto.Decrypt(username); password = crypto.Decrypt(password); try { //user credentials checking ClinicDAL.UserAuthendication UA = new ClinicDAL.UserAuthendication(username, password); if (UA.ValidUser) { dr["Flag"] = true; dr["Message"] = UIClasses.Messages.LoginSuccess; loginMsg.Columns.Add("ClinicID", typeof(String)); dr["ClinicID"] = UA.ClinicID; } else { dr["Flag"] = false; dr["Message"] = UIClasses.Messages.LoginFailed; } } catch (Exception ex) { dr["Flag"] = false; dr["Message"] = ex.Message; //exception message to be passed as JSON } finally { //returning data loginMsg.Rows.Add(dr); ds.Tables.Add(loginMsg); } return getDbDataAsJSON(ds); }
public String getDbDataAsJSON(DataSet ds) { ClinicDAL.CryptographyFunctions crypto = new ClinicDAL.CryptographyFunctions(); try { DataTable dt = ds.Tables[0]; System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row; foreach (DataRow dr in dt.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName, dr[col]); } rows.Add(row); } this.Context.Response.ContentType = ""; return "[" + crypto.Encrypt(serializer.Serialize(rows)) + "]"; } catch (Exception) { return ""; } finally { } }