async Task IProjectGrain.PostProjectProceeds(ProjectProceeds source) { if (Kernel == null) { throw new ProjectNotFoundException(); } if (!await IsMyProject()) { throw new SecurityException("非请毋加!"); } if (source.InvoiceAmount > Kernel.ContAmount - Kernel.TotalInvoiceAmount) { throw new ValidationException(String.Format("本开票金额({0})已超过{1}可开数额({2})!", source.InvoiceAmount, Kernel.ProjectName, Kernel.ContAmount - Kernel.TotalInvoiceAmount)); } Database.Execute((DbTransaction dbTransaction) => { source.InsertSelf(dbTransaction); Kernel.UpdateSelf(dbTransaction, NameValue.Set <ProjectInfo>(p => p.TotalInvoiceAmount, p => p.TotalInvoiceAmount + source.InvoiceAmount)); }); ProjectProceedsList.Add(source); }
async Task IProjectGrain.DeleteProjectProceeds(long id) { if (Kernel == null) { throw new ProjectNotFoundException(); } if (!await IsMyProject()) { throw new SecurityException("非请毋删!"); } ProjectProceeds projectProceeds = null; foreach (ProjectProceeds item in ProjectProceedsList) { if (item.Id == id) { projectProceeds = item; break; } } if (projectProceeds == null) { throw new ValidationException(String.Format("未找到 {0} 可删除的开票记录!", Kernel.ProjectName)); } Database.Execute((DbTransaction dbTransaction) => { projectProceeds.DeleteSelf(dbTransaction); Kernel.UpdateSelf(dbTransaction, NameValue.Set <ProjectInfo>(p => p.TotalInvoiceAmount, p => p.TotalInvoiceAmount - projectProceeds.InvoiceAmount)); }); ProjectProceedsList.Remove(projectProceeds); }