Ejemplo n.º 1
0
        public async Task <ActionResult> UpdateAsync([FromBody] PurchaseOrderDetailDTO purchaseOrderDetail, CancellationToken cancellationToken)
        {
            InitUserInfo();
            if (!AllowUpdate)
            {
                return(ValidationProblem());
            }
            var specFilter = new PurchaseOrderDetailFilterSpecification(int.Parse(purchaseOrderDetail.Id), true);
            var rowCount   = await _purchaseOrderDetailService.CountAsync(specFilter, cancellationToken);

            if (rowCount == 0)
            {
                throw new EntityNotFoundException(nameof(PurchaseOrderDetail), purchaseOrderDetail.Id);
            }

            // bind to old item


            var objItem = _mapper.Map <PurchaseOrderDetail>(purchaseOrderDetail);

            // untuk data yang mereference object, perlu di set null agar tidak insert sebagai data baru
            CleanReferenceObject(objItem);

            var result = await _purchaseOrderDetailService.PatchDraft(objItem, cancellationToken);

            if (!result)
            {
                AssignToModelState(_purchaseOrderDetailService.Errors);
                return(ValidationProblem());
            }

            return(CreatedAtAction(nameof(GetIdAsync), new { id = objItem.Id }, null));
        }