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")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } //var tb_客户 = _pinhua2.tb_往来表.FirstOrDefault(m => m.RecordId == 客户.RecordId); //_mapper.Map<vm_客户, tb_往来表>(客户, tb_客户); //Common.ModelHelper.CompleteMainOnEdit(tb_客户); _pinhua2.funcEditRecord <vm_客户, tb_往来表>(客户); try { _pinhua2.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!sys往来表Exists(客户.RecordId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } //var remote = _pinhua2.tb_字典表.FirstOrDefault(m => m.RecordId == vm_字典.RecordId); //if (remote == null) // return NotFound(); // 非空字段赋值给跟踪实体 //_mapper.Map<vm_字典, tb_字典表>(vm_字典, remote); if (_pinhua2.funcEditRecord <vm_字典, tb_字典表>(vm_字典) == null) { return(NotFound()); } //// 删除旧明细 //var tb_字典表D列表 = _pinhua2.tb_字典表D.Where(p => p.RecordId == vm_字典.RecordId); //_pinhua2.tb_字典表D.RemoveRange(tb_字典表D列表); //// 插入新明细 //foreach (var item in vm_字典D列表) //{ // Common.ModelHelper.CompleteDetailOnUpdate(remote, item); // item.字典名 = vm_字典.字典名; // item.组 = vm_字典.组; //} //_pinhua2.tb_字典表D.AddRange(_mapper.Map<IList<tb_字典表D>>(vm_字典D列表)); _pinhua2.funcEditDetails <vm_字典, vm_字典D, tb_字典表, tb_字典表D>(vm_字典, vm_字典D列表, creatingD => { creatingD.字典号 = vm_字典.字典号; creatingD.组号 = vm_字典.组号; }); // 保存改变 try { _pinhua2.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tb_字典表Exists(vm_字典.RecordId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } _pinhua2.funcNewRecord <vm_供应商, tb_往来表>(供应商, BeforeNew: local => { local.往来号 = _pinhua2.funcAutoCode("往来号"); local.类型 = "供应商"; }); _pinhua2.SaveChanges(); return(RedirectToPage("./Index")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } //Common.ModelHelper.CompleteMainOnCreate(客户); //客户.往来号 = _pinhua2.funcAutoCode("往来号"); //客户.类型 = "客户"; //_pinhua2.tb_往来表.Add(_mapper.Map<tb_往来表>(客户)); _pinhua2.funcNewRecord <vm_客户, tb_往来表>(客户, creating => { creating.往来号 = _pinhua2.funcAutoCode("往来号"); creating.类型 = "客户"; }); _pinhua2.SaveChanges(); return(RedirectToPage("./Index")); }
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")); }