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 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 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 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 DeleteAasCustomerInfo([FromBody] Dictionary 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; } } }