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 async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var remote = _context.funcEditRecord <vm_收款单, tb_收付表>(Record, before => { before.类型 = "收款"; before.往来 = _context.tb_往来表.AsNoTracking().FirstOrDefault(p => p.往来号 == Record.往来号)?.简称; }); _context.funcEditDetails <vm_收款单, vm_收款单D, tb_收付表, tb_收付表D>(Record, RecordDs, creatingD => { if (string.IsNullOrEmpty(creatingD.子单号)) // 子单号为空的,表示新插入 { creatingD.子单号 = _context.funcAutoCode("子单号"); } else if (!string.IsNullOrEmpty(creatingD.子单号)) // 子单号不为空,表示从报价单引入,插入 { } }, updatingD => { }, deletingD => { }); try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!tb_收付表Exists(Record.RecordId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }