21 changed files with 667 additions and 180 deletions
@ -0,0 +1,154 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using AMESCoreStudio.WebApi; |
|||
using AMESCoreStudio.WebApi.Models.AMES; |
|||
using AMESCoreStudio.CommonTools.Result; |
|||
|
|||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|||
{ //YIRU 2022-09-20
|
|||
/// <summary>
|
|||
/// 設備上傳圖檔資料表
|
|||
/// </summary>
|
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class OutfitInfoBlobController : ControllerBase |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
public OutfitInfoBlobController(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
// GET: api/OutfitInfoBlob
|
|||
[HttpGet] |
|||
public async Task<ActionResult<IEnumerable<OutfitInfoBlob>>> GetOutfitInfoBlobs() |
|||
{ |
|||
return await _context.OutfitInfoBlobs.ToListAsync(); |
|||
} |
|||
|
|||
// GET: api/OutfitInfoBlob/5
|
|||
[HttpGet("{id}")] |
|||
public async Task<ActionResult<OutfitInfoBlob>> GetOutfitInfoBlob(int id) |
|||
{ |
|||
var OutfitInfoBlob = await _context.OutfitInfoBlobs.FindAsync(id); |
|||
|
|||
if (OutfitInfoBlob == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
return OutfitInfoBlob; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 設備上傳圖檔資料表 By OutfitID
|
|||
/// </summary>
|
|||
/// <param name="id">OutfitID</param>
|
|||
/// <returns></returns>
|
|||
[HttpGet("ByOutfitID/{id}")] |
|||
public async Task<ActionResult<IEnumerable<OutfitInfoBlob>>> GetOutfitInfoBlobByOutfitID(int id) |
|||
{ |
|||
var OutfitInfoBlobs = await _context.OutfitInfoBlobs.Where(w => w.OutfitID == id).ToListAsync(); |
|||
return OutfitInfoBlobs; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 更新上傳圖檔資料
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="OutfitInfoBlob"></param>
|
|||
/// <returns></returns>
|
|||
// PUT: api/OutfitInfoes/5
|
|||
// To protect from overposting attacks, enable the specific properties you want to bind to, for
|
|||
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
|
|||
[HttpPut("{id}")] |
|||
public async Task<ResultModel<OutfitInfoBlob>> PutOutfitInfo(int id, [FromBody] OutfitInfoBlob OutfitInfoBlob) |
|||
{ |
|||
ResultModel<OutfitInfoBlob> result = new ResultModel<OutfitInfoBlob>(); |
|||
if (id != OutfitInfoBlob.OutfitID) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "序號錯誤"; |
|||
return result; |
|||
} |
|||
|
|||
_context.Entry(OutfitInfoBlob).State = EntityState.Modified; |
|||
|
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
|
|||
result.Success = false; |
|||
result.Msg = ex.Message; |
|||
return result; |
|||
|
|||
} |
|||
|
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
return result; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 新增 設備上傳圖檔資料表
|
|||
/// </summary>
|
|||
/// <param name="OutfitInfoBlob"></param>
|
|||
/// <returns></returns>
|
|||
[HttpPost] |
|||
public async Task<ResultModel<OutfitInfoBlob>> PostOutfitInfoBlob(OutfitInfoBlob OutfitInfoBlob) |
|||
{ |
|||
ResultModel<OutfitInfoBlob> result = new ResultModel<OutfitInfoBlob>(); |
|||
OutfitInfoBlob.CreateDate = DateTime.Now; |
|||
OutfitInfoBlob.UpdateDate = DateTime.Now; |
|||
|
|||
_context.OutfitInfoBlobs.Add(OutfitInfoBlob); |
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = ex.InnerException.Message; |
|||
} |
|||
return result; |
|||
} |
|||
/// <summary>
|
|||
/// 刪除 設備上上傳圖檔資料表
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
|
|||
[HttpDelete("{id}")] |
|||
public async Task<ActionResult<OutfitInfoBlob>> DeleteOutfitInfoBlob(int id) |
|||
{ |
|||
var OutfitInfoBlob = await _context.OutfitInfoBlobs.FindAsync(id); |
|||
if (OutfitInfoBlob == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
_context.OutfitInfoBlobs.Remove(OutfitInfoBlob); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
return OutfitInfoBlob; |
|||
} |
|||
|
|||
private bool OutfitInfoBlobExists(int id) |
|||
{ |
|||
return _context.OutfitInfoBlobs.Any(e => e.OutfitID == id); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,92 @@ |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.ComponentModel.DataAnnotations.Schema; |
|||
using System.Runtime.Serialization; |
|||
using Microsoft.EntityFrameworkCore; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace AMESCoreStudio.WebApi.Models.AMES |
|||
{ // YIRU 2022-90-20
|
|||
/// <summary>
|
|||
/// 設備圖
|
|||
/// </summary>
|
|||
[Table("OUTFIT_INFO_BLOB", Schema = "JHAMES")] |
|||
public partial class OutfitInfoBlob |
|||
{ |
|||
/// <summary>
|
|||
/// 治具ID
|
|||
/// </summary>
|
|||
[Column("OUTFIT_ID")] |
|||
[DataMember] |
|||
[Key] |
|||
[Required] |
|||
|
|||
public int OutfitID { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 檔名
|
|||
/// </summary>
|
|||
[Column("IMAGE_NAME")] |
|||
[StringLength(50)] |
|||
[Display(Name = "檔名")] |
|||
[DataMember] |
|||
[Required(ErrorMessage = "{0},不能空白")] |
|||
public string ImageName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 新檔名
|
|||
/// </summary>
|
|||
[Column("NEWNAME")] |
|||
[DataMember] |
|||
public string NewName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 圖檔
|
|||
/// </summary>
|
|||
[Column("IMAGE_BLOB")] |
|||
[StringLength(50)] |
|||
[Display(Name = "圖檔")] |
|||
[DataMember] |
|||
public byte[] ImageBlob { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 儲存路徑
|
|||
/// </summary>
|
|||
[Column("FILEPATH")] |
|||
[StringLength(100)] |
|||
[Display(Name = "儲存路徑")] |
|||
[DataMember] |
|||
public string FilePath { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 創建者ID
|
|||
/// </summary>
|
|||
[Column("CREATE_USERID")] |
|||
[DataMember] |
|||
public int CreateUserID { get; set; } = 0; |
|||
|
|||
/// <summary>
|
|||
/// 創建日期
|
|||
/// </summary>
|
|||
[Column("CREATE_DATE")] |
|||
[DataMember] |
|||
public DateTime CreateDate { get; set; } = System.DateTime.Now; |
|||
|
|||
/// <summary>
|
|||
/// 更新者ID
|
|||
/// </summary>
|
|||
[Column("UPDATE_USERID")] |
|||
[DataMember] |
|||
public int UpdateUserID { get; set; } = 0; |
|||
|
|||
/// <summary>
|
|||
/// 更新日期
|
|||
/// </summary>
|
|||
[Column("UPDATE_DATE")] |
|||
[DataMember] |
|||
public DateTime UpdateDate { get; set; } = System.DateTime.Now; |
|||
} |
|||
} |
Loading…
Reference in new issue