初始化
This commit is contained in:
120
SupplierManager/Controllers/AasCustomerInfoesController.cs
Normal file
120
SupplierManager/Controllers/AasCustomerInfoesController.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SupplierManager.Models;
|
||||
using ViewModels;
|
||||
|
||||
namespace SupplierManager.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class AasCustomerInfoesController : ControllerBase
|
||||
{
|
||||
private readonly AgentApprovalSystemContext _context;
|
||||
|
||||
public AasCustomerInfoesController(AgentApprovalSystemContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/AasCustomerInfoes
|
||||
[HttpGet]
|
||||
public async Task<ReturnInfo> GetAasCustomerInfos([FromBody] QueryAll_Or_Single S)
|
||||
{
|
||||
ReturnInfo returnInfo = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
returnInfo.isok = true;
|
||||
if (S.IsAll)
|
||||
{
|
||||
returnInfo.response = await _context.AasCustomerInfos.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var aasCustomerInfo = await _context.AasCustomerInfos.FindAsync(S.ID);
|
||||
|
||||
returnInfo.response = aasCustomerInfo;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
returnInfo.isok = false;
|
||||
returnInfo.message = ex.Message;
|
||||
}
|
||||
return returnInfo;
|
||||
}
|
||||
|
||||
|
||||
// PUT: api/AasCustomerInfoes/5
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPut("{id}")]
|
||||
public async Task<ReturnInfo> PutAasCustomerInfo([FromBody] AasCustomerInfo aasCustomerInfo)
|
||||
{
|
||||
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
_context.Entry(aasCustomerInfo).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
// POST: api/AasCustomerInfoes
|
||||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
|
||||
[HttpPost]
|
||||
public async Task<ReturnInfo> AddAasCustomerInfo([FromBody] AasCustomerInfo aasCustomerInfo)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
_context.AasCustomerInfos.Add(aasCustomerInfo);
|
||||
await _context.SaveChangesAsync();
|
||||
r.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.message = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
[HttpPost()]
|
||||
public async Task<ReturnInfo> DeleteAasCustomerInfo([FromBody] Dictionary<string, long> stu)
|
||||
{
|
||||
ReturnInfo re = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
|
||||
long id = stu["id"];
|
||||
re.isok = true;
|
||||
var aasCustomerInfo = await _context.AasCustomerInfos.FindAsync(id);
|
||||
|
||||
if (aasCustomerInfo != null)
|
||||
{
|
||||
_context.AasCustomerInfos.Remove(aasCustomerInfo);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
re.isok = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
re.isok = false;
|
||||
}
|
||||
return re;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user