public async Task <AjaxResult> Add([FromBody] PurchaseOrderInputDto dto)
        {
            return(await AjaxResult.Business(async result =>
            {
                Check.NotNull(dto, nameof(dto));
                Check.NotNull(dto.Items, nameof(dto.Items));
                dto.Id = Guid.NewGuid();
                if (!ModelState.IsValid)
                {
                    result.Error("提交信息验证失败");
                    return;
                }
                if (dto.Items == null || dto.Items.Length <= 0)
                {
                    result.Error("采购单至少需要一个采购项");
                    return;
                }

                foreach (var item in dto.Items)
                {
                    item.Id = Guid.NewGuid();
                    item.PurchaseOrderId = dto.Id;
                }
                if (String.IsNullOrWhiteSpace(dto.Operator))
                {
                    dto.Operator = User.Identity.Name;
                }
                dto.DateTime = DateTime.Now;
                await _purchaseOrderContract.AddPurchaseOrderAsync(dto);
                result.Type = AjaxResultType.Success;
            }));
        }
        public async Task <AjaxResult> Update([FromBody] PurchaseOrderInputDto dto)
        {
            return(await AjaxResult.Business(async result =>
            {
                Check.NotNull(dto, nameof(dto));

                if (!ModelState.IsValid)
                {
                    result.Error("提交信息验证失败");
                    return;
                }

                if (String.IsNullOrWhiteSpace(dto.Operator))
                {
                    dto.Operator = User.Identity.Name;
                }
                dto.DateTime = DateTime.Now;
                foreach (var item in dto.Items)
                {
                    item.PurchaseOrderId = dto.Id;
                }
                await _purchaseOrderContract.UpdatePurchaseOrderAsync(dto);
                result.Type = AjaxResultType.Success;
                if (dto == null)
                {
                    result.Error("找不到指定的采购单信息");
                }
                else
                {
                    result.Success(dto);
                }
            }));
        }
        public async Task <bool> UpdatePurchaseOrderAsync(PurchaseOrderInputDto dto)
        {
            var purchaseOrder = dto.MapTo <PurchaseOrder>();
            await _purchaseOrderRepo.UpdateAsync(purchaseOrder);

            var items = dto.Items.Select(d => d.MapTo <PurchaseOrderItem>()).ToArray();
            await _purchaseOrderItemRepo.UpdateAsync(items);

            return(true);
        }
        public async Task <bool> AddPurchaseOrderAsync(PurchaseOrderInputDto dto)
        {
            if (dto.Items == null || dto.Items.Length <= 0)
            {
                return(false);
            }

            var purchaseOrder = dto.MapTo <PurchaseOrder>();
            var items         = dto.Items.Select(d => d.MapTo <PurchaseOrderItem>()).ToArray();
            //foreach(var item in items)
            //{
            //    item.PurchaseOrderId = purchaseOrder.Id;
            //}
            await _purchaseOrderRepo.InsertAsync(purchaseOrder);

            await _purchaseOrderItemRepo.InsertAsync(items);

            return(true);
        }