internal void UpdateBinCurrentPounds(BinLoad binLoad = null, BinDisbursement binDisb = null) { var binId = 0; var currentTicket = 0; var lastDisbDate = new DateTime(1 / 1 / 1900); var lastLoaded = new DateTime(1 / 1 / 1900); if (binLoad == null) { // update for bin disbursement binId = binDisb.BinID; lastDisbDate = binDisb.DisbursementDate; } else { // update for bin load binId = binLoad.BinID; currentTicket = binLoad.TicketNumber; lastLoaded = binLoad.DateLoaded; } var totalDisbs = 0; var totalAdds = 0; if (DbContext.BinDisbursements.Any(x => x.BinID == binId)) { totalDisbs = DbContext.BinDisbursements.Where(x => x.BinID == binId).Sum(x => x.Pounds); } if (DbContext.BinLoads.Any(x => x.BinID == binId)) { totalAdds = DbContext.BinLoads.Where(x => x.BinID == binId).Sum(x => x.PoundsLoaded); } var bin = DbContext.Bins.Single(x => x.BinID == binId); bin.CurrentPounds = totalAdds - totalDisbs; bin.CurrentTicket = binLoad != null ? currentTicket : bin.CurrentTicket; bin.LastDisbursement = binDisb != null ? lastDisbDate : bin.LastDisbursement; bin.LastLoaded = binLoad != null ? lastLoaded : bin.LastLoaded; DbContext.SaveChanges(); }
private List <DbValidationError> GetBinDisbursementErrors(BinRepository pr, BinDisbursement bd, BinDisbursementDto dto, int companyId, int PondId) { bd.ProcessRecord(dto); return(pr.Validate(bd)); }