public static void SaveLicensesPayRates(DSModel db, KeyBinder key, List <CompanyLicensePayRateModel> rates) { if (db == null) { throw new ArgumentNullException("db"); } if (key == null) { throw new ArgumentNullException("key"); } if (rates == null) { throw new ArgumentNullException("rates"); } if (rates.Count == 0) { return; } uint[] distCompanies = rates.Select(c => c.CompanyID).Distinct().ToArray(); uint[] oldIDs = rates.Select(c => c.CompanyDriverID).ToArray(); db.CompaniesLicensesPayrates.Where(c => distCompanies.Contains(c.CompanyID) && !oldIDs.Contains(c.CompanyDriverID)).DeleteAll(); foreach (var pay in rates.Where(r => r.CompanyDriverID == 0)) { CompaniesLicensesPayrate poco = new DAL.CompaniesLicensesPayrate(); poco.CompanyID = pay.CompanyID; poco.LicenseID = pay.LicenseID; poco.PayRate = pay.PayRate; poco.PayRateOT = pay.PayRateOT; poco.FromDate = pay.FromDate; poco.ToDate = pay.ToDate; key.AddKey(poco, pay, pay.GetName(p => p.CompanyDriverID)); db.Add(poco); } foreach (var pay in rates.Where(r => r.CompanyDriverID != 0)) { CompaniesLicensesPayrate poco = db.CompaniesLicensesPayrates.Where(r => r.CompanyDriverID == pay.CompanyDriverID).FirstOrDefault(); poco.CompanyID = pay.CompanyID; poco.LicenseID = pay.LicenseID; poco.PayRate = pay.PayRate; poco.PayRateOT = pay.PayRateOT; poco.FromDate = pay.FromDate; poco.ToDate = pay.ToDate; } }
public static void SaveLicensesPayRates(DSModel db, KeyBinder key, List<CompanyLicensePayRateModel> rates) { if (db == null) throw new ArgumentNullException("db"); if (key == null) throw new ArgumentNullException("key"); if (rates == null) throw new ArgumentNullException("rates"); if (rates.Count == 0) return; uint[] distCompanies = rates.Select(c => c.CompanyID).Distinct().ToArray(); uint[] oldIDs = rates.Select(c => c.CompanyDriverID).ToArray(); db.CompaniesLicensesPayrates.Where(c => distCompanies.Contains(c.CompanyID) && !oldIDs.Contains(c.CompanyDriverID)).DeleteAll(); foreach (var pay in rates.Where(r => r.CompanyDriverID == 0)) { CompaniesLicensesPayrate poco = new DAL.CompaniesLicensesPayrate(); poco.CompanyID = pay.CompanyID; poco.LicenseID = pay.LicenseID; poco.PayRate = pay.PayRate; poco.PayRateOT = pay.PayRateOT; poco.FromDate = pay.FromDate; poco.ToDate = pay.ToDate; key.AddKey(poco, pay, pay.GetName(p => p.CompanyDriverID)); db.Add(poco); } foreach (var pay in rates.Where(r => r.CompanyDriverID != 0)) { CompaniesLicensesPayrate poco = db.CompaniesLicensesPayrates.Where(r => r.CompanyDriverID == pay.CompanyDriverID).FirstOrDefault(); poco.CompanyID = pay.CompanyID; poco.LicenseID = pay.LicenseID; poco.PayRate = pay.PayRate; poco.PayRateOT = pay.PayRateOT; poco.FromDate = pay.FromDate; poco.ToDate = pay.ToDate; } }