179 lines
5.4 KiB
C#
179 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using birzha_contracts.Models;
|
|
using System.Net.Http;
|
|
using Newtonsoft.Json;
|
|
using System.Text;
|
|
|
|
namespace birzha_contracts.Controllers
|
|
{
|
|
public class ContractsController : Controller
|
|
{
|
|
private readonly MvcContractContext _context;
|
|
private static readonly HttpClient client = new HttpClient();
|
|
|
|
public ContractsController(MvcContractContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
|
|
public async Task<IActionResult> Push(){
|
|
var contracts = await _context.Contract.Take(10).ToListAsync();
|
|
|
|
|
|
var data = JsonConvert.SerializeObject(contracts);
|
|
|
|
var content = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
|
|
|
|
var response = await client.PostAsync("http://127.0.0.1:8000/api/contract/import", content);
|
|
|
|
ViewData["response"] = await response.Content.ReadAsStringAsync();
|
|
|
|
return View();
|
|
}
|
|
|
|
// GET: Contracts
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
return _context.Contract != null ?
|
|
View(await _context.Contract.Take(1000).ToListAsync()) :
|
|
Problem("Entity set 'MvcContractContext.Contract' is null.");
|
|
}
|
|
|
|
// GET: Contracts/Details/5
|
|
public async Task<IActionResult> Details(long? id)
|
|
{
|
|
if (id == null || _context.Contract == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var contract = await _context.Contract
|
|
.FirstOrDefaultAsync(m => m.ID == id);
|
|
if (contract == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return View(contract);
|
|
}
|
|
|
|
// GET: Contracts/Create
|
|
public IActionResult Create()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
// POST: Contracts/Create
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Create([Bind("ID,InputNumber,InputDate,RegNumber,RegDate,MarkerSpec,Workflow_ID,Note,Remark")] Contract contract)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
_context.Add(contract);
|
|
await _context.SaveChangesAsync();
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
return View(contract);
|
|
}
|
|
|
|
// GET: Contracts/Edit/5
|
|
public async Task<IActionResult> Edit(long? id)
|
|
{
|
|
if (id == null || _context.Contract == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var contract = await _context.Contract.FindAsync(id);
|
|
if (contract == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
return View(contract);
|
|
}
|
|
|
|
// POST: Contracts/Edit/5
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Edit(long id, [Bind("ID,InputNumber,InputDate,RegNumber,RegDate,MarkerSpec,Workflow_ID,Note,Remark")] Contract contract)
|
|
{
|
|
if (id != contract.ID)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
_context.Update(contract);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
catch (DbUpdateConcurrencyException)
|
|
{
|
|
if (!ContractExists(contract.ID))
|
|
{
|
|
return NotFound();
|
|
}
|
|
else
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
return View(contract);
|
|
}
|
|
|
|
// GET: Contracts/Delete/5
|
|
public async Task<IActionResult> Delete(long? id)
|
|
{
|
|
if (id == null || _context.Contract == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var contract = await _context.Contract
|
|
.FirstOrDefaultAsync(m => m.ID == id);
|
|
if (contract == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return View(contract);
|
|
}
|
|
|
|
// POST: Contracts/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
{
|
|
if (_context.Contract == null)
|
|
{
|
|
return Problem("Entity set 'MvcContractContext.Contract' is null.");
|
|
}
|
|
var contract = await _context.Contract.FindAsync(id);
|
|
if (contract != null)
|
|
{
|
|
_context.Contract.Remove(contract);
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
|
|
private bool ContractExists(long id)
|
|
{
|
|
return (_context.Contract?.Any(e => e.ID == id)).GetValueOrDefault();
|
|
}
|
|
}
|
|
}
|