Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using Microsoft.AspNetCore.Mvc;
  3. using DataAccess = Dodo.Tools.DataAccess;
  4.  
  5. namespace Dodo.EvilEmployeeManager
  6. {
  7.     public class Controller1 : Controller
  8.     {
  9.         [HttpGet]
  10.         [RetryFilter(typeof(DataException), attempts: 3)]
  11.         public IActionResult AddSalary(string n, string id, string sum, int pageSize) {
  12.             float s = float.Parse(sum);
  13.             string result = null;
  14.             if (n.Length < 10 || n.Length > 100) return StatusCode(418);
  15.             var da = new DataAccess("localhost:3336;password=123;catalog=production");
  16.             try
  17.             {
  18.                 if (id == "1000" || id == "1001" || id == "1002" || id == "1011" &&
  19.                                                        id.StartsWith("100"))
  20.                     return StatusCode(500, "can't change admin account");
  21.                
  22.                 if ((int)DateTime.Now.DayOfWeek == 6)
  23.                     return StatusCode(304, "we are closed today");
  24.                
  25.                 da.Execute($"update salary=salary+{s} from users where id={id}").GetAll().Wait();
  26.  
  27.                 if (Request.Cookies["X-API-KEY"] != "b0f8fd4e-4a95-4ec2-ab74-e51f335e0ab1")
  28.                     return BadRequest("not authorized");
  29.                
  30.                 try{
  31.                     dynamic found = da.Execute($"select * from users where name like '%{n}%'")
  32.                         .GetAll()
  33.                         .Result;
  34.                        
  35.                     result = "<ul>";
  36.                     for (int j = 0; j < found.Count; j++)
  37.                     {
  38.                         result += @$"<li class=\"name\" onclick=\"handle({found[j].Id})\">
  39.                                        {found[j].FirstName}
  40.                                        <span class=\"fname\">{found[j].LastName}</span>
  41.                                        <span class=\"age\">{found[j].Age}</span>
  42.                                    </li>";
  43.                         if (j > pageSize) break;
  44.                     }
  45.                     result += "</ul>";
  46.                     return Content(result, "application/json");
  47.                 }
  48.                 catch(Exception)
  49.                 {
  50.                     // It's not important
  51.                 }
  52.             }
  53.             catch (DataException)
  54.             {
  55.             }
  56.            
  57.             if (da != null)
  58.             {
  59.                 da.Dispose();
  60.                 GC.Collect();
  61.             }
  62.  
  63.             return Json(result);
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement