Esempio n. 1
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var remote = _pinhua2.funcNewRecord <vm_字典, tb_字典表>(vm_字典);

            if (_pinhua2.SaveChanges() > 0)
            {
                // 保存后获取自增主键RecordId
                // 补完明细表,主表字段写入明细表
                foreach (var localD in vm_字典D列表)
                {
                    _pinhua2.funcNewDetail <vm_字典, vm_字典D, tb_字典表, tb_字典表D>(remote, localD, BeforeNewD: beforeD =>
                    {
                        beforeD.字典号 = remote.字典号;
                        beforeD.组号  = remote.组号;
                    });
                }
                // 再次保存
                _pinhua2.SaveChanges();
            }
            else
            {
                return(NotFound());
            }

            #region comment
            //// 补完字段
            //Common.ModelHelper.CompleteMainOnCreate(vm_字典);
            //// 映射为实体类型
            //var tb_字典 = _mapper.Map<tb_字典表>(vm_字典);
            //// 插入
            //_pinhua2.tb_字典表.Add(tb_字典);
            //// 保存
            //if (_pinhua2.SaveChanges() > 0)
            //{
            //    // 保存后获取自增主键RecordId
            //    // 补完明细表,主表字段写入明细表
            //    foreach (var item in vm_字典D列表)
            //    {
            //        Common.ModelHelper.CompleteDetailOnCreate(tb_字典, item);
            //        item.字典名 = vm_字典.字典名;
            //        item.组 = vm_字典.组;
            //    }
            //    // 插入明细表
            //    _pinhua2.tb_字典表D.AddRange(_mapper.Map<IList<tb_字典表D>>(vm_字典D列表));
            //    // 再次保存
            //    _pinhua2.SaveChanges();
            //}
            //else
            //    return NotFound();
            #endregion

            return(RedirectToPage("./Index"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            //Common.ModelHelper.CompleteMainOnCreate(vm_销售报价);
            //vm_销售报价.单号 = _context.funcAutoCode("订单号");
            //vm_销售报价.业务类型 = "销售报价";
            //vm_销售报价.往来 = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == vm_销售报价.往来号)?.简称;
            //var tb_报价 = _mapper.Map<tb_报价表>(vm_销售报价);
            //_context.tb_报价表.Add(tb_报价);

            var tb_报价 = _context.funcNewRecord <vm_销售报价, tb_报价表>(vm_Main, before =>
            {
                before.单号   = _context.funcAutoCode("订单号");
                before.业务类型 = "销售报价";
                before.往来   = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == vm_Main.往来号)?.简称;
            });

            if (_context.SaveChanges() > 0)
            {
                foreach (var item in vm_Details)
                {
                    _context.funcNewDetail <vm_销售报价, vm_销售报价D, tb_报价表, tb_报价表D>(tb_报价, item, beforeNewD =>
                    {
                        beforeNewD.子单号 = _context.funcAutoCode("子单号");
                    });
                    Common.ModelHelper.CompleteDetailOnCreate(tb_报价, item);
                }
                //_context.tb_报价表D.AddRange(_mapper.Map<IList<tb_报价表D>>(vm_销售报价D列表));
                await _context.SaveChangesAsync();
            }
            else
            {
                return(NotFound());
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var remote = _context.funcNewRecord <vm_收款单, tb_收付表>(vm_Main, creating =>
            {
                creating.单号 = _context.funcAutoCode("订单号");
                creating.类型 = "收款";
                creating.往来 = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == vm_Main.往来号)?.简称;
            });

            if (await _context.SaveChangesAsync() > 0)
            {
                foreach (var localD in vm_Details)
                {
                    _context.funcNewDetail <vm_收款单, vm_收款单D, tb_收付表, tb_收付表D>(remote, localD, BeforeNewD: beforeD =>
                    {
                        if (string.IsNullOrEmpty(beforeD.子单号))
                        {
                            beforeD.子单号 = _context.funcAutoCode("子单号");
                        }
                        else
                        {
                            //var 报价D = _context.tb_报价表D.FirstOrDefault(d => d.子单号 == beforeD.子单号);
                            //if (报价D != null)
                            //    报价D.状态 = "已下单";
                        }
                    });
                }
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var remote = _context.funcNewRecord <vm_销售出库, tb_IO>(vm_Main, creating =>
            {
                creating.类型 = "销售出库";
                creating.单号 = _context.funcAutoCode("订单号");
                creating.往来 = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == vm_Main.往来号)?.简称;
            });

            if (await _context.SaveChangesAsync() > 0)
            {
                foreach (var localD in vm_Details)
                {
                    _context.funcNewDetail <vm_销售出库, vm_销售出库D, tb_IO, tb_IOD>(remote, localD, creatingD => {
                        var 报价D = _context.tb_订单表D.FirstOrDefault(d => d.子单号 == creatingD.子单号);
                        if (报价D != null)
                        {
                            报价D.状态 = "已出库";
                        }
                    });
                }
                await _context.SaveChangesAsync();
            }
            else
            {
                return(NotFound());
            }

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var remote = _context.funcNewRecord <vm_销售订单, tb_订单表>(Record, BeforeNew: creating =>
            {
                creating.单号   = _context.funcAutoCode("订单号");
                creating.业务类型 = "销售订单";
                creating.往来   = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == Record.往来号)?.简称;
            });

            if (await _context.SaveChangesAsync() > 0)
            {
                foreach (var localD in RecordDs)
                {
                    _context.funcNewDetail <vm_销售订单, vm_销售订单D, tb_订单表, tb_订单表D>(remote, localD, BeforeNewD: beforeD =>
                    {
                        if (string.IsNullOrEmpty(beforeD.子单号))
                        {
                            beforeD.子单号 = _context.funcAutoCode("子单号");
                        }
                        else
                        {
                            var 报价D = _context.tb_报价表D.FirstOrDefault(d => d.子单号 == beforeD.子单号);
                            if (报价D != null)
                            {
                                报价D.状态 = "已下单";
                            }
                        }
                    });
                }
                await _context.SaveChangesAsync();
            }
            else
            {
                return(NotFound());
            }

            #region OldWay
            //Common.ModelHelper.CompleteMainOnCreate(vm_销售订单);
            //vm_销售订单.单号 = _context.funcAutoCode("订单号");
            //vm_销售订单.业务类型 = "销售订单";
            //vm_销售订单.往来 = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == vm_销售订单.往来号)?.简称;
            //var tb_订单 = _mapper.Map<tb_订单表>(vm_销售订单);
            //_context.tb_订单表.Add(tb_订单);
            //if (_context.SaveChanges() > 0)
            //{
            //    foreach (var item in vm_销售订单D列表)
            //    {
            //        Common.ModelHelper.CompleteDetailOnCreate(tb_订单, item);
            //        if (string.IsNullOrEmpty(item.子单号))
            //            item.子单号 = _context.funcAutoCode("子单号");
            //        else
            //        {
            //            var remoteD = _context.tb_报价表D.FirstOrDefault(d => d.子单号 == item.子单号);
            //            if (remoteD != null)
            //                remoteD.状态 = "已下单";
            //        }
            //    }
            //    _context.tb_订单表D.AddRange(_mapper.Map<IList<tb_订单表D>>(vm_销售订单D列表));
            //    await _context.SaveChangesAsync();
            //}
            //else
            //    return NotFound();
            #endregion

            return(RedirectToPage("./Index"));
        }