如何在使用Rest API时避免使用Put / Patch对每个更新进行验证检查

时间:2019-03-09 08:12:18

标签: asp.net rest asp.net-web-api asp.net-core

我正在Rest-API中创建一个Asp.net core并面临一个乏味的问题。 我每次put/patch时都要验证自己的数据。

SupplyOrderState发生更改时,数据将被更新。 每次我必须检查

  1. 所有RelationalIds有效
  2. 状态不能后退
  3. 一旦批准订单,您将无法编辑
  4. 检查订购的产品是否有效

public class SupplyOrder : BaseEntity
{
    public long SupplierId { get; set; }
    public Supplier Supplier { get; set; }

    public DateTime CreationDate { get; set; }
    public DateTime? DeliveredDate { get; set; }
    public DateTime? CancellationDate { get; set; }

    public long CostCenterId { get; set; }
    public CostCenter CostCenter { get; set; }

    public SupplyOrderStates SupplyOrderStates { get; set; }

    public string ApproverUserId { get; set; }
    public ApplicationUser ApproverUser { get; set; }

    public string CancellerUserId { get; set; }
    public ApplicationUser CancellerUser { get; set; }

    public string ReceiverUserId { get; set; }
    public ApplicationUser ReceiverUser { get; set; }

    public ICollection<SupplyOrderDetail> SupplyOrderDetails { get; set; }
    public ICollection<SupplyTransportationDocument> SupplyTransportationDocuments { get; set; }
}


 public enum SupplyOrderStates
{
    preApproved = 0,
    approved = 1,
    notApproved = 2,
    delivered = 3,
    partialDelivered = 4,
    cancled = 5
}

0 个答案:

没有答案