Esempio n. 1
0
        public static void SaveInvoicePayRates(DSModel db, KeyBinder key, List <CompanyInvoicingPayRateModel> 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.CompanyInvoicingID).ToArray();
            db.CompaniesInvoicingPayrates.Where(c => distCompanies.Contains(c.CompanyID) && !oldIDs.Contains(c.CompanyInvoicingID)).DeleteAll();

            foreach (var pay in rates.Where(r => r.CompanyInvoicingID == 0))
            {
                CompaniesInvoicingPayrate poco = new DAL.CompaniesInvoicingPayrate();
                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.CompanyInvoicingID));
                db.Add(poco);
            }

            foreach (var pay in rates.Where(r => r.CompanyInvoicingID != 0))
            {
                CompaniesInvoicingPayrate poco = db.CompaniesInvoicingPayrates.Where(r => r.CompanyInvoicingID == pay.CompanyInvoicingID).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 SaveInvoicePayRates(DSModel db, KeyBinder key, List<CompanyInvoicingPayRateModel> 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.CompanyInvoicingID).ToArray();
            db.CompaniesInvoicingPayrates.Where(c => distCompanies.Contains(c.CompanyID) && !oldIDs.Contains(c.CompanyInvoicingID)).DeleteAll();

            foreach (var pay in rates.Where(r => r.CompanyInvoicingID == 0))
            {
                CompaniesInvoicingPayrate poco = new DAL.CompaniesInvoicingPayrate();
                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.CompanyInvoicingID));
                db.Add(poco);
            }

            foreach (var pay in rates.Where(r => r.CompanyInvoicingID != 0))
            {
                CompaniesInvoicingPayrate poco = db.CompaniesInvoicingPayrates.Where(r => r.CompanyInvoicingID == pay.CompanyInvoicingID).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;
            }
        }