예제 #1
0
        public async Task <ActionResult> UpdateDraftAsync(int id, [FromBody] PurchaseRequestDetailDTO purchaseRequestDetailDto, CancellationToken cancellationToken = default)
        {
            InitUserInfo();
            if (!AllowCreate && !AllowUpdate)
            {
                return(ValidationProblem());
            }
            var specFilter = new PurchaseRequestDetailFilterSpecification(int.Parse(purchaseRequestDetailDto.Id), true);
            var rowCount   = await _purchaseRequestDetailService.CountAsync(specFilter, cancellationToken);

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

            var purchaseRequestDetail = _mapper.Map <PurchaseRequestDetail>(purchaseRequestDetailDto);
            var result = await _purchaseRequestDetailService.PatchDraft(purchaseRequestDetail, cancellationToken);

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

            return(CreatedAtAction(nameof(GetIdAsync), new { id = id }, null));
        }
예제 #2
0
        public async Task <ActionResult> UpdateAsync([FromBody] PurchaseRequestDetailDTO purchaseRequestDetail, CancellationToken cancellationToken)
        {
            InitUserInfo();
            if (!AllowUpdate)
            {
                return(ValidationProblem());
            }
            var specFilter = new PurchaseRequestDetailFilterSpecification(int.Parse(purchaseRequestDetail.Id), true);
            var rowCount   = await _purchaseRequestDetailService.CountAsync(specFilter, cancellationToken);

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

            // bind to old item


            var objItem = _mapper.Map <PurchaseRequestDetail>(purchaseRequestDetail);

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

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

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

            return(CreatedAtAction(nameof(GetIdAsync), new { id = objItem.Id }, null));
        }
예제 #3
0
        public async Task <ActionResult> CreateDraftAsync([FromBody] PurchaseRequestDetailDTO purchaseRequestDetail, CancellationToken cancellationToken)
        {
            InitUserInfo();
            if (!AllowCreate)
            {
                return(ValidationProblem());
            }
            var newItem = _mapper.Map <PurchaseRequestDetail>(purchaseRequestDetail);

            newItem = await _purchaseRequestDetailService.CreateDraft(newItem, cancellationToken);

            if (newItem == null)
            {
                AssignToModelState(_purchaseRequestDetailService.Errors);
                return(ValidationProblem());
            }

            return(Ok(_mapper.Map <PurchaseRequestDetailDTO>(newItem)));
        }
예제 #4
0
        public async Task <ActionResult> CreateAsync([FromBody] PurchaseRequestDetailDTO purchaseRequestDetail, CancellationToken cancellationToken)
        {
            InitUserInfo();
            if (!AllowCreate)
            {
                return(ValidationProblem());
            }
            // remove temporary id (if any)

            var newItem = _mapper.Map <PurchaseRequestDetail>(purchaseRequestDetail);

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

            newItem = await _purchaseRequestDetailService.CreateDraft(newItem, cancellationToken);

            if (newItem == null)
            {
                AssignToModelState(_purchaseRequestDetailService.Errors);
                return(ValidationProblem());
            }

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