11 changed files with 906 additions and 556 deletions
@ -0,0 +1,123 @@ |
|||||
|
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.WebApi.DTO.AMES; |
||||
|
using AMESCoreStudio.CommonTools.Result; |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Controllers.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 工單上傳圖檔資料表
|
||||
|
/// </summary>
|
||||
|
[Route("api/[controller]")]
|
||||
|
[ApiController] |
||||
|
public class WipInfoBlobController : ControllerBase |
||||
|
{ |
||||
|
private readonly AMESContext _context; |
||||
|
|
||||
|
public WipInfoBlobController(AMESContext context) |
||||
|
{ |
||||
|
_context = context; |
||||
|
} |
||||
|
|
||||
|
// GET: api/WipInfoBlob
|
||||
|
[HttpGet] |
||||
|
public async Task<ActionResult<IEnumerable<WipInfoBlob>>> GetWipInfoBlobs() |
||||
|
{ |
||||
|
return await _context.WipInfoBlobs.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
// GET: api/WipInfoBlob/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<IEnumerable<WipInfoBlob>>> GetWipInfoBlob(int id) |
||||
|
{ |
||||
|
var wipInfoBlob = await _context.WipInfoBlobs.Where(w => w.WipID == id).ToListAsync(); |
||||
|
return wipInfoBlob; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新工單上傳圖檔資料表
|
||||
|
/// </summary>
|
||||
|
/// <param name="wipInfoBlob"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPut("{id}")] |
||||
|
public async Task<ResultModel<WipInfoBlob>> PutWipInfoBlob(WipInfoBlob wipInfoBlob) |
||||
|
{ |
||||
|
ResultModel<WipInfoBlob> result = new ResultModel<WipInfoBlob>(); |
||||
|
_context.Entry(wipInfoBlob).State = EntityState.Modified; |
||||
|
//設置容器空間某一個模型的某一個欄位 不提交到資料庫
|
||||
|
//DbContent.Entry是要更新到資料庫的整個對象
|
||||
|
_context.Entry<WipInfoBlob>(wipInfoBlob).Property("CreateDate").IsModified = false; |
||||
|
_context.Entry<WipInfoBlob>(wipInfoBlob).Property("CreateUserID").IsModified = false; |
||||
|
wipInfoBlob.UpdateDate = DateTime.Now; |
||||
|
wipInfoBlob.UpdateUserID = 0; |
||||
|
|
||||
|
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="wipInfoBlob"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
public async Task<ResultModel<WipInfoBlob>> PostWipInfoBlob(WipInfoBlob wipInfoBlob) |
||||
|
{ |
||||
|
ResultModel<WipInfoBlob> result = new ResultModel<WipInfoBlob>(); |
||||
|
_context.WipInfoBlobs.Add(wipInfoBlob); |
||||
|
try |
||||
|
{ |
||||
|
await _context.SaveChangesAsync(); |
||||
|
result.Success = true; |
||||
|
result.Msg = "OK"; |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
result.Success = false; |
||||
|
result.Msg = ex.InnerException.Message; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// DELETE: api/WipInfoBlob/5
|
||||
|
[HttpDelete("{id}")] |
||||
|
public async Task<ActionResult<WipInfoBlob>> DeleteWipInfoBlob(int id) |
||||
|
{ |
||||
|
var wipInfoBlob = await _context.WipInfoBlobs.FindAsync(id); |
||||
|
if (wipInfoBlob == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
_context.WipInfoBlobs.Remove(wipInfoBlob); |
||||
|
await _context.SaveChangesAsync(); |
||||
|
|
||||
|
return wipInfoBlob; |
||||
|
} |
||||
|
|
||||
|
private bool WipInfoBlobExists(int id) |
||||
|
{ |
||||
|
return _context.WipInfoBlobs.Any(e => e.WipID == id); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,82 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using System.ComponentModel.DataAnnotations.Schema; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using System.Runtime.Serialization; |
||||
|
#nullable disable |
||||
|
|
||||
|
namespace AMESCoreStudio.WebApi.Models.AMES |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 工單上傳圖檔資料表
|
||||
|
/// </summary>
|
||||
|
[Keyless] |
||||
|
[Table("WIP_INFO_BLOB", Schema = "JHAMES")] |
||||
|
public partial class WipInfoBlob |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 工單ID
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Column("WIP_ID")] |
||||
|
[DataMember] |
||||
|
public int WipID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 圖檔名稱
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Required] |
||||
|
[Column("IMAGE_NAME")] |
||||
|
[StringLength(50)] |
||||
|
[DataMember] |
||||
|
public string ImageName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 圖檔
|
||||
|
/// </summary>
|
||||
|
[Column("IMAGE_BLOB", TypeName = "BLOB")] |
||||
|
[DataMember] |
||||
|
public byte[] ImageBlob { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 上傳路徑
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
[Column("FILEPATH")] |
||||
|
[StringLength(100)] |
||||
|
[DataMember] |
||||
|
public string Filepath { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立UserID
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_USERID")] |
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
public int CreateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立日期
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
[Column("CREATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime CreateDate { get; set; } = DateTime.Now; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新UserID
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_USERID")] |
||||
|
[DataMember] |
||||
|
public int UpdateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新日期
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime? UpdateDate { get; set; } = DateTime.Now; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue