コード例 #1
0
ファイル: ElixController.cs プロジェクト: Sahjome/Elixir
 public HttpResponseMessage Announcement()
 {
     try
     {
         string query = "select * from announcements";
         cmd = new MySqlCommand(query, con);
         con.Open();
         read = cmd.ExecuteReader();
         if (read.HasRows)
         {
             read.Close();
             adapter = new MySqlDataAdapter(cmd);
             var cot = adapter.Fill(dt);
             if (cot > 0)
             {
                 var data = ToDict.Table(dt);
                 //List<Dictionary<string,string>> data =new  List<Dictionary<to.Table(dt)>();
                 response.description = "success";
                 response.status      = HttpStatusCode.OK;
                 response.pairs       = data;
                 con.Close();
                 var mess = Request.CreateResponse(response);
                 return(mess);
             }
             else
             {
                 response.description = "failed";
                 response.status      = HttpStatusCode.BadRequest;
                 //response.pair = data;
                 con.Close();
                 var mess = Request.CreateResponse(response);
                 return(mess);
             }
         }
         else
         {
             response.description = "No records";
             response.status      = HttpStatusCode.OK;
             //response.pair = data;
             con.Close();
             var mess = Request.CreateResponse(response);
             return(mess);
         }
     }
     catch (Exception ex)
     {
         response.description = "Failed " + ex.Message;
         response.status      = HttpStatusCode.BadRequest;
         //response.pair = data;
         //con.Close();
         var mess = Request.CreateResponse(response);
         return(mess);
     }
 }
コード例 #2
0
ファイル: ElixController.cs プロジェクト: Sahjome/Elixir
 public HttpResponseMessage LogProf(Dictionary <string, object> data)
 {
     try
     {
         string query = "select Username, Firstname, Surname, Sex, Email, Address from profiles where (Email=@Entry or Username=@Entry and Password=@Password)";
         cmd = new MySqlCommand(query, con);
         cmd.Parameters.AddWithValue("Entry", data["username"]);
         cmd.Parameters.AddWithValue("Password", data["password"]);
         con.Open();
         adapter = new MySqlDataAdapter(cmd);
         adapter.Fill(dt);
         //read = cmd.ExecuteReader();
         if (dt.Rows.Count > 0)
         {
             response.description = "success";
             response.status      = HttpStatusCode.OK;
             response.pairs       = ToDict.Table(dt);
             con.Close();
             return(Request.CreateResponse(response));
         }
         else
         {
             response.description = "login failed";
             response.status      = HttpStatusCode.BadRequest;
             con.Close();
             return(Request.CreateResponse(response));
         }
     }
     catch (Exception ex)
     {
         response.description = "login failed " + ex.Message;
         response.status      = HttpStatusCode.BadRequest;
         con.Close();
         return(Request.CreateResponse(response));
     }
 }