Advertisement
tim_ryspekov

Placer API sourcecode

Feb 12th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Net.Http;
  9. using System.Net.Mail;
  10. using System.Web;
  11. using System.Web.Http;
  12.  
  13. namespace placer.Controllers
  14. {
  15.    
  16.     public class ValuesController : ApiController
  17.     {
  18.         // GET api/values
  19.         public IEnumerable<string> Get()
  20.         {
  21.             return new string[] { "value1", "value2" };
  22.         }
  23.  
  24.         // GET api/values/5
  25.         public string Get(string id)
  26.         {
  27.             try
  28.             {
  29.                 string result = "";
  30.                 if (id == "1")
  31.                 {
  32.                     string tablename = "razdel_placer";
  33.                     SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  34.  
  35.                     con2.Open();
  36.                     SqlCommand myOleDbCommand;
  37.                     myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename, con2);
  38.  
  39.  
  40.                     SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  41.                     MyOleDbAdapter.SelectCommand = myOleDbCommand;
  42.  
  43.                     DataSet r = new DataSet();
  44.                     MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  45.                     MyOleDbAdapter.Fill(r, "MainTable");
  46.                     for (int i = 0; i < r.Tables[0].Rows.Count; i++)
  47.                     {
  48.                         if (result != "")
  49.                         {
  50.                             result += '*';
  51.                         }
  52.                         result += (r.Tables[0].Rows[i]["razd"].ToString()+"#"+ r.Tables[0].Rows[i]["location"].ToString());
  53.  
  54.                         con2.Close();
  55.  
  56.  
  57.  
  58.                     }
  59.                 }
  60.                 else
  61.                 {
  62.  
  63.                     string[] h = id.Split('=');
  64.                     if (h[0] == "2")
  65.                     {
  66.                         string tablename = "login_placer";
  67.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  68.  
  69.                         con2.Open();
  70.                         SqlCommand myOleDbCommand;
  71.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE login like'" + h[1].ToLower() + "'", con2);
  72.  
  73.  
  74.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  75.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  76.  
  77.                         DataSet r = new DataSet();
  78.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  79.                         MyOleDbAdapter.Fill(r, "MainTable");
  80.                         if (r.Tables[0].Rows.Count != 0)
  81.                         {
  82.                             con2.Close();
  83.                             return "0";
  84.                         }
  85.                         else
  86.                         {
  87.                             myOleDbCommand = new SqlCommand("INSERT INTO  " + tablename + " (login,pass,mail) VALUES ('" + h[1].ToLower() + "','" + h[3] + "','" + tom(h[2].ToLower()) + "')", con2);
  88.                             myOleDbCommand.ExecuteNonQuery();
  89.                             con2.Close();
  90.                             return "1";
  91.                         }
  92.                     }
  93.                     else if (h[0] == "3")
  94.                     {
  95.                         string tablename = "login_placer";
  96.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  97.  
  98.                         con2.Open();
  99.                         SqlCommand myOleDbCommand;
  100.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE login like '" + h[1].ToLower() + "' AND pass like '" + h[2] + "'", con2);
  101.  
  102.  
  103.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  104.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  105.  
  106.                         DataSet r = new DataSet();
  107.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  108.                         MyOleDbAdapter.Fill(r, "MainTable");
  109.                         if (r.Tables[0].Rows.Count != 0)
  110.                         {
  111.                             con2.Close();
  112.                             return "1";
  113.                         }
  114.                         else
  115.                         {
  116.                             return "0";
  117.                         }
  118.                     }
  119.                     else if (h[0] == "4")
  120.                     {
  121.                         string tablename = "login_placer";
  122.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  123.  
  124.                         con2.Open();
  125.                         SqlCommand myOleDbCommand;
  126.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE login like '" + h[1].ToLower() + "'", con2);
  127.  
  128.  
  129.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  130.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  131.  
  132.                         DataSet r = new DataSet();
  133.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  134.                         MyOleDbAdapter.Fill(r, "MainTable");
  135.                         if (r.Tables[0].Rows.Count != 0)
  136.                         {
  137.                             Random rand = new Random();
  138.                             string s = "";
  139.                             string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  140.                             for (int j = 0; j < 8; j++)
  141.                             {
  142.                                 s += Alphabet[rand.Next(Alphabet.Length)];
  143.  
  144.  
  145.                             }
  146.                             string mail = r.Tables[0].Rows[0]["mail"].ToString();
  147.                             SendMail(mail, "Восстановление пароля MyTalent", "Временный пароль: " + s.ToLower());
  148.                             myOleDbCommand = new SqlCommand("Update " + tablename + " SET pass='" + s.ToLower() + "' WHERE login LIKE '" + h[1].ToLower() + "'", con2);
  149.  
  150.                             myOleDbCommand.ExecuteNonQuery();
  151.                             return "1";
  152.                         }
  153.                         else
  154.                         {
  155.                             return "0";
  156.                         }
  157.                     }
  158.                     else if (h[0] == "5")
  159.                     {
  160.                         string tablename = "post_placer";
  161.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  162.  
  163.                         con2.Open();
  164.                         SqlCommand myOleDbCommand;
  165.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE razd like '" + h[1] + "'", con2);
  166.  
  167.  
  168.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  169.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  170.  
  171.                         DataSet r = new DataSet();
  172.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  173.                         MyOleDbAdapter.Fill(r, "MainTable");
  174.                         for (int i = 0; i < r.Tables[0].Rows.Count; i++)
  175.                         {
  176.                             if (result != "")
  177.                             {
  178.                                 result += '*';
  179.                             }
  180.                             result += (r.Tables[0].Rows[i]["zag"].ToString() + "=" + r.Tables[0].Rows[i]["aut"].ToString() + "=" + r.Tables[0].Rows[i]["txt"].ToString() + "=" + r.Tables[0].Rows[i]["likes"].ToString() + "=" + r.Tables[0].Rows[i]["users"].ToString() + "=" + r.Tables[0].Rows[i]["id_p"].ToString());
  181.  
  182.                             con2.Close();
  183.  
  184.  
  185.  
  186.                         }
  187.                         return result;
  188.                     }
  189.                     else if (h[0] == "6")
  190.                     {
  191.                         string tablename = "login_placer";
  192.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  193.  
  194.                         con2.Open();
  195.                         SqlCommand myOleDbCommand;
  196.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE login like '" + h[1].ToLower() + "'", con2);
  197.  
  198.  
  199.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  200.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  201.  
  202.                         DataSet r = new DataSet();
  203.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  204.                         MyOleDbAdapter.Fill(r, "MainTable");
  205.                         if (r.Tables[0].Rows.Count != 0)
  206.                         {
  207.  
  208.  
  209.                             myOleDbCommand = new SqlCommand("Update " + tablename + " SET pass='" + h[2] + "' WHERE login LIKE '" + h[1].ToLower() + "'", con2);
  210.  
  211.                             myOleDbCommand.ExecuteNonQuery();
  212.                             return "1";
  213.                         }
  214.                         else
  215.                         {
  216.                             return "0";
  217.                         }
  218.                     }
  219.                     else if (h[0] == "7")
  220.                     {
  221.                         string tablename = "login_placer";
  222.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  223.  
  224.                         con2.Open();
  225.                         SqlCommand myOleDbCommand;
  226.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE login like '" + h[1].ToLower() + "'", con2);
  227.  
  228.  
  229.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  230.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  231.  
  232.                         DataSet r = new DataSet();
  233.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  234.                         MyOleDbAdapter.Fill(r, "MainTable");
  235.                         if (r.Tables[0].Rows.Count != 0)
  236.                         {
  237.  
  238.  
  239.                             myOleDbCommand = new SqlCommand("Update " + tablename + " SET mail='" + tom(h[2].ToLower()) + "' WHERE login LIKE '" + h[1].ToLower() + "'", con2);
  240.  
  241.                             myOleDbCommand.ExecuteNonQuery();
  242.                             return "1";
  243.                         }
  244.                         else
  245.                         {
  246.                             return "0";
  247.                         }
  248.                     }
  249.                     else if (h[0] == "8")
  250.                     {
  251.                         string tablename = "post_placer";
  252.                         SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  253.  
  254.                         con2.Open();
  255.                         SqlCommand myOleDbCommand;
  256.                         myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE id_p like '" + h[2].ToLower() + "'", con2);
  257.  
  258.  
  259.                         SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  260.                         MyOleDbAdapter.SelectCommand = myOleDbCommand;
  261.  
  262.                         DataSet r = new DataSet();
  263.                         MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  264.                         MyOleDbAdapter.Fill(r, "MainTable");
  265.  
  266.                         var user = r.Tables[0].Rows[0]["users"].ToString().Split('&');
  267.                         for (int i = 0; i < user.Length; i++)
  268.                         {
  269.                             if (user[i].ToLower() == h[1].ToLower())
  270.                             {
  271.                                 con2.Close();
  272.                                 return "0";
  273.                             }
  274.                         }
  275.                         var new_s = "";
  276.                         if (r.Tables[0].Rows[0]["users"].ToString().Length == 0)
  277.                         {
  278.                             new_s = h[1].ToLower();
  279.                         }
  280.                         else
  281.                         {
  282.                             new_s = r.Tables[0].Rows[0]["users"].ToString() + "&" + h[1];
  283.                         }
  284.  
  285.                         int likes = Convert.ToInt32(r.Tables[0].Rows[0]["likes"].ToString());
  286.                         likes++;
  287.                         myOleDbCommand = new SqlCommand("Update " + tablename + " SET likes='" + likes.ToString() + "', users='" + new_s + "' WHERE id_p LIKE '" + h[2].ToLower() + "'", con2);
  288.  
  289.                         myOleDbCommand.ExecuteNonQuery();
  290.  
  291.                         con2.Close();
  292.                         return "1";
  293.                     }
  294.                 }
  295.                 return result;
  296.             }
  297.             catch (Exception r)
  298.             {
  299.                 return r.Message;
  300.             }
  301.  
  302.         }
  303.      
  304.        
  305.         string tom(string s)
  306.         {
  307.             string s1 = "";
  308.             for (int i = 0; i < s.Length; i++)
  309.             {
  310.                 if (s[i] == ',')
  311.                 {
  312.                     s1 += '.';
  313.                 }
  314.                 else
  315.                 {
  316.                     s1 += s[i];
  317.                 }
  318.             }
  319.             return s1;
  320.         }
  321.  
  322.         // POST api/values
  323.         public string Post([FromBody]string value)
  324.         {
  325.  
  326.             string req_txt = "";
  327.             using (StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream))
  328.             {
  329.                 req_txt = reader.ReadToEnd();
  330.             }
  331.             string[] h = req_txt.Split('>');
  332.             if (h.Length > 1)
  333.             {
  334.                 string tablename = "post_placer";
  335.                 SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  336.                 con2.Open();
  337.                 SqlCommand myOleDbCommand;
  338.                 myOleDbCommand = new SqlCommand("SELECT zag" + " FROM " + tablename, con2);
  339.  
  340.  
  341.                 SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  342.                 MyOleDbAdapter.SelectCommand = myOleDbCommand;
  343.  
  344.                 DataSet r = new DataSet();
  345.                 MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  346.                 MyOleDbAdapter.Fill(r, "MainTable");
  347.  
  348.  
  349.  
  350.                 myOleDbCommand = new SqlCommand("INSERT INTO  " + tablename + " (razd,aut,zag,txt,likes,users,id_p) VALUES (N'" + h[1] + "', N'" + h[0] + "', N'" + h[2] + "', N'" + h[3] + "', '0', '', '" + (r.Tables[0].Rows.Count + 1).ToString() + "')", con2);
  351.                 myOleDbCommand.ExecuteNonQuery();
  352.                 con2.Close();
  353.                 return "1";
  354.             }
  355.             else
  356.             {
  357.                 string result = "";
  358.                 string tablename = "post_placer";
  359.                 SqlConnection con2 = new SqlConnection("Server=192.186.88.146,1433;Database=lic_edu;User ID=test; Password=123;");
  360.  
  361.                 con2.Open();
  362.                 SqlCommand myOleDbCommand;
  363.                 myOleDbCommand = new SqlCommand("SELECT*" + " FROM " + tablename + " WHERE razd like N'" + h[0].ToLower() + "'", con2);
  364.  
  365.  
  366.                 SqlDataAdapter MyOleDbAdapter = new SqlDataAdapter();
  367.                 MyOleDbAdapter.SelectCommand = myOleDbCommand;
  368.  
  369.                 DataSet r = new DataSet();
  370.                 MyOleDbAdapter.TableMappings.Add(tablename, "MainTable");
  371.                 MyOleDbAdapter.Fill(r, "MainTable");
  372.                 for (int i = 0; i < r.Tables[0].Rows.Count; i++)
  373.                 {
  374.                     if (result != "")
  375.                     {
  376.                         result += '<';
  377.                     }
  378.                     result += (r.Tables[0].Rows[i]["zag"].ToString() + ">" + r.Tables[0].Rows[i]["aut"].ToString() + ">" + r.Tables[0].Rows[i]["txt"].ToString() + ">" + r.Tables[0].Rows[i]["likes"].ToString() + ">" + r.Tables[0].Rows[i]["users"].ToString() + ">" + r.Tables[0].Rows[i]["id_p"].ToString());
  379.  
  380.                  
  381.  
  382.  
  383.  
  384.                 }
  385.                 con2.Close();
  386.                 return result;
  387.             }
  388.  
  389.         }
  390.        
  391.         // PUT api/values/5
  392.         public void Put(int id, [FromBody]string value)
  393.         {
  394.         }
  395.  
  396.         // DELETE api/values/5
  397.         public void Delete(int id)
  398.         {
  399.         }
  400.     }
  401. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement