Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "ConnectionStrings": {
- "MySQL": "server=localhost;port=3307;user=root;password=root;database=JarekDB"
- },
- "Logging": {
- "LogLevel": {
- "Default": "Information",
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- }
- },
- "AllowedHosts": "*"
- }
- //Enable CORS
- services.AddCors(c =>
- {
- c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
- });
- //JSON Serializer
- services.AddControllersWithViews().AddNewtonsoftJson(options =>
- options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
- .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver
- = new DefaultContractResolver());
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using MySqlConnector;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- namespace MySqlWebApi.Controllers
- {
- [Route("api/[controller]")]
- [ApiController]
- public class UserController : ControllerBase
- {
- private readonly IConfiguration _configuration;
- public UserController(IConfiguration configuration)
- {
- _configuration = configuration;
- }
- [HttpGet]
- public JsonResult Get()
- {
- string query = @"select * from users";
- string sqlDataSource = _configuration.GetConnectionString("MySQL");
- DataTable table = new DataTable();
- MySqlDataReader myReader;
- using (MySqlConnection myCon = new MySqlConnection(sqlDataSource))
- {
- myCon.Open();
- using (MySqlCommand myCommand = new MySqlCommand(query, myCon))
- {
- myReader = myCommand.ExecuteReader();
- table.Load(myReader);
- myReader.Close();
- myCon.Close();
- }
- }
- return new JsonResult(table);
- }
- [HttpGet("{id}")]
- public JsonResult GetUser(int id)
- {
- string query = @"select * from users where id="+id;
- string sqlDataSource = _configuration.GetConnectionString("MySQL");
- DataTable table = new DataTable();
- MySqlDataReader myReader;
- using (MySqlConnection myCon = new MySqlConnection(sqlDataSource))
- {
- myCon.Open();
- using (MySqlCommand myCommand = new MySqlCommand(query, myCon))
- {
- myReader = myCommand.ExecuteReader();
- table.Load(myReader);
- myReader.Close();
- myCon.Close();
- }
- }
- return new JsonResult(table);
- }
- }
- }
- class Samochod
- {
- public string marka;
- public int predkosc;
- public void Przyspiesz(int a)
- {
- predkosc += a;
- }
- public static Samochod operator + (Samochod s1, Samochod s2)
- {
- Samochod s3 = new Samochod();
- ...
- ...
- return s3;
- }
- ...
- ...
Add Comment
Please, Sign In to add comment