public override void OnCreating(Models.FpRegradingResultDocs model) { //do //{ // model.Code = CodeGenerator.GenerateCode(); //} //while (this.DbSet.Any(d => d.Code.Equals(model.Code))); try { base.OnCreating(model); model._CreatedAgent = "Service"; model._CreatedBy = this.Username; model._LastModifiedAgent = "Service"; model._LastModifiedBy = this.Username; FpRegradingResultDetailsDocsService fpReturProInvDocsDetailsService = ServiceProvider.GetService <FpRegradingResultDetailsDocsService>(); fpReturProInvDocsDetailsService.Username = this.Username; foreach (FpRegradingResultDocsDetails data in model.Details) { fpReturProInvDocsDetailsService.OnCreating(data); } } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } }
public override async Task <int> DeleteModel(int Id) { int Count = 0; using (var Transaction = this.DbContext.Database.BeginTransaction()) { try { Models.FpRegradingResultDocs fpReturProInvDocs = await ReadModelById(Id); Count = this.Delete(Id); FpRegradingResultDetailsDocsService fpReturProInvDocsDetailsService = ServiceProvider.GetService <FpRegradingResultDetailsDocsService>(); fpReturProInvDocsDetailsService.Username = this.Username; HashSet <int> fpReturProInvDocsDetails = new HashSet <int>(this.DbContext.fpRegradingResultDocsDetails.Where(p => p.FpReturProInvDocsId.Equals(Id)).Select(p => p.Id)); foreach (int detail in fpReturProInvDocsDetails) { await fpReturProInvDocsDetailsService.DeleteAsync(detail); } CreateInventoryDocument(fpReturProInvDocs, "OUT"); Transaction.Commit(); } catch (DbUpdateConcurrencyException) { Transaction.Rollback(); throw; } } return(Count); }