\Api\kriptitco\Controllers\RaspipController.cs

Return Back
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using DataAccess;
using kriptitco.Models;
using Microsoft.Extensions.Configuration;

namespace kriptitco.Controllers
{
public class RaspipController : Controller
{
private readonly Access _context;
private readonly IConfiguration _configuration;

public RaspipController(Access context, IConfiguration configuration)
{
_context = context;
_configuration = configuration;
}

[HttpGet]
public IActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(Kullanici kullanici)
{
var ad = _configuration.GetSection("Kullanici").GetSection("Ad").Value;

var sifre = _configuration.GetSection("Kullanici").GetSection("Sifre").Value;

if (kullanici.KullaniciAd != ad || kullanici.Sifre != sifre)
{
return View();
}

var raspipList = _context.RaspIp.OrderBy(r => r.Id).AsEnumerable().ToList();
var raspIpCount = raspipList.Count;

var sayac = 0;

foreach (var raspIp in raspipList)
{
sayac += 1;

if (sayac >= raspIpCount || !(raspIp.Tarih.Subtract(raspipList[sayac].Tarih).TotalMilliseconds > -5000))
{
continue;
}

_context.RaspIp.Remove(raspIp);
raspipList.Remove(raspIp);
_context.SaveChanges();
}

ViewData["RaspIpList"] = raspipList;

return View();
}

[HttpGet]
public JsonResult GetServerIpPort(string apiKey)
{
if (apiKey != _configuration.GetSection("Api").GetSection("Key").Value)
{
return Json(null);
}

var serverIpPort = _context.ServerIpPort.FirstOrDefault();

return Json(serverIpPort);
}

[HttpPost]
public string PostServerIpPort(string apiKey, string ip, string port)
{
if (apiKey != _configuration.GetSection("Api").GetSection("Key").Value)
{
return "False";
}

var serverIpPort = _context.ServerIpPort.FirstOrDefault();

if (serverIpPort == null)
{
return "False";
}

serverIpPort.Ip = ip;
serverIpPort.Port = port;
_context.Update(serverIpPort);
_context.SaveChanges();

return "True";
}
}
}