コード例 #1
0
        private static void InsertBlob(DSModel db, KeyBinder key, FileBlobModel model)
        {
            key.AddRollback(model.BlobID, model, model.GetName(p => p.BlobID));
            FileBlob poco = new FileBlob();

            model.Map(poco);
            db.Add(poco);

            key.AddKey(poco, model, model.GetName(p => p.BlobID));
        }
コード例 #2
0
        private static Location InsertLocation(DSModel db, KeyBinder key, LocationModel model, Company company = null)
        {
            Location poco = new Location();

            poco.LocationName = model.LocationName;
            if (model.LocationCode == string.Empty)
            {
                poco.LocationCode = "L" + LocationRepository.PeekLocationCode(db, "L");
            }
            else
            {
                poco.LocationCode = model.LocationCode;
            }

            if (company == null)
            {
                poco.CompanyID = model.CompanyID;
            }
            else
            {
                poco.Company = company;
            }

            poco.LocationAddress = model.LocationAddress;
            poco.LocationPhone   = model.LocationPhone;
            poco.LocationFax     = model.LocationFax;

            if (model.ConfirmationContact.IsChanged)
            {
                poco.ConfirmationContact = ContactRepository.SaveContact(db, key, model.ConfirmationContact);
                key.AddKey(poco.ConfirmationContact, model.ConfirmationContact, poco.ConfirmationContact.GetName(p => p.ContactID));
                key.AddKey(poco.ConfirmationContact, model, poco.ConfirmationContact.GetName(p => p.ContactID), model.GetName(p => p.ConfirmationContactID));
            }
            if (model.InvoiceContact.IsChanged)
            {
                poco.InvoiceContact = ContactRepository.SaveContact(db, key, model.InvoiceContact);
                key.AddKey(poco.InvoiceContact, model.InvoiceContact, poco.InvoiceContact.GetName(p => p.ContactID));
                key.AddKey(poco.InvoiceContact, model, poco.InvoiceContact.GetName(p => p.ContactID), model.GetName(p => p.InvoiceContactID));
            }
            if (model.DispatchContact.IsChanged)
            {
                poco.DispatchContact = ContactRepository.SaveContact(db, key, model.DispatchContact);
                key.AddKey(poco.DispatchContact, model.DispatchContact, poco.DispatchContact.GetName(p => p.ContactID));
                key.AddKey(poco.DispatchContact, model, poco.DispatchContact.GetName(p => p.ContactID), model.GetName(p => p.DispatchContactID));
            }

            poco.TravelPay           = model.TravelPay;
            poco.TravelPayName       = model.TravelPayName;
            poco.LunchTime           = model.LunchTime;
            poco.IsEnabled           = model.IsEnabled;
            poco.IncludeConfirmation = model.IncludeConfirmation;
            db.Add(poco);
            key.AddKey(poco, model, model.GetName(p => p.LocationID));
            return(poco);
        }
コード例 #3
0
        private static void InsertMedical(DSModel db, KeyBinder key, DriverMedicalModel model)
        {
            DriversMedical poco = new DriversMedical();

            model.Map(poco);
            db.Add(poco);

            key.AddKey(poco, model, model.GetName(p => p.DriverMedicalID));
            db.FlushChanges();
            SaveReminders(db, key, model, poco);
        }
コード例 #4
0
        private static Contact InsertContact(DSModel db, KeyBinder key, ContactModel model)
        {
            Contact poco = new Contact();

            poco.ContactName  = model.ContactName;
            poco.ContactPhone = model.ContactPhone;
            poco.ContactEmail = model.ContactEmail;
            db.Add(poco);
            key.AddKey(poco, model, model.GetName(p => p.ContactID));
            return(poco);
        }
コード例 #5
0
        private static void InsertDriverLicense(DSModel db, KeyBinder key, DriverLicenseModel model)
        {
            var poco = new DriversLicense();

            model.Map(poco);
            db.Add(poco);
            key.AddKey(poco, model, model.GetName(p => p.DriverLicenseID));
            db.FlushChanges();

            SaveDriverLicensePermits(db, key, poco, model);
            SaveDriverLicenseReminders(db, key, poco, model);
        }
コード例 #6
0
        private static void InsertInvoice(DSModel db, KeyBinder key, InvoiceModel model)
        {
            var poco = new Invoice();

            poco.CompanyID         = model.CompanyID;
            poco.LocationID        = model.LocationID;
            poco.InvoiceTypeID     = model.InvoiceTypeID;
            poco.InvoiceNumber     = InvoiceRepository.NextNumber(db, model);
            poco.InvoiceIssueDate  = model.InvoiceIssueDate;
            poco.InvoicePeriodFrom = model.InvoicePeriodFrom;
            poco.InvoicePeriodTo   = model.InvoicePeriodTo;
            poco.InvoiceNote       = model.InvoiceNote;
            poco.LateCharge        = model.LateCharge;
            poco.LateChargeDays    = model.LateChargeDays;
            poco.IsConfirmed       = model.IsConfirmed;
            poco.UserID            = model.UserID;
            poco.LastUpdateTime    = model.LastUpdateTime;
            key.AddKey(poco, model, model.GetName(p => p.InvoiceID));
            db.Add(poco);

            foreach (var d in model.Details)
            {
                var det = new InvoicesDetail();
                det.InvoiceDetailDate          = d.InvoiceDetailDate;
                det.InvoiceDetailName          = d.InvoiceDetailName;
                det.InvoiceDetailTotalTime     = d.InvoiceDetailTotalTime;
                det.InvoiceDetailOverTime      = d.InvoiceDetailOverTime;
                det.InvoiceDetailRegularRate   = d.InvoiceDetailRegularRate;
                det.InvoiceDetailOverRate      = d.InvoiceDetailOverRate;
                det.InvoiceDetailRegularPay    = d.InvoiceDetailRegularPay;
                det.InvoiceDetailOvertimePay   = d.InvoiceDetailOvertimePay;
                det.InvoiceDetailGroupName     = d.InvoiceDetailGroupName;
                det.InvoiceDetailGroupPosition = d.InvoiceDetailGroupPosition;
                det.Invoice = poco;
                key.AddKey(det, d, d.GetName(p => p.InvoiceDetailID));
                key.AddKey(poco, d, d.GetName(p => p.InvoiceID));
                poco.InvoicesDetails.Add(det);
                db.Add(det);
            }
        }
コード例 #7
0
        private static void InsertUser(DSModel db, KeyBinder key, UserModel user)
        {
            User poco = new User();

            poco.Username   = user.Username;
            poco.Password   = UserRepository.HashPassword(user.Username, user.Password);
            poco.FirstName  = user.FirstName;
            poco.SecondName = user.SecondName;
            poco.LastName   = user.LastName;
            poco.IsEnabled  = user.IsEnabled;
            poco.IsAdmin    = user.IsAdmin;
            key.AddKey(poco, user, user.GetName(p => p.UserID));
            db.Add(poco);
        }
コード例 #8
0
        private static void UpdateInvoice(DSModel db, KeyBinder key, InvoiceModel model)
        {
            var poco = db.Invoices.Where(i => i.InvoiceID == model.InvoiceID).FirstOrDefault();

            if (poco == null)
            {
                throw new ArgumentException("No invoice with the specified ID!");
            }

            poco.CompanyID         = model.CompanyID;
            poco.LocationID        = model.LocationID;
            poco.InvoiceTypeID     = model.InvoiceTypeID;
            poco.InvoiceNumber     = model.InvoiceNumber;
            poco.InvoiceIssueDate  = model.InvoiceIssueDate;
            poco.InvoicePeriodFrom = model.InvoicePeriodFrom;
            poco.InvoicePeriodTo   = model.InvoicePeriodTo;
            poco.InvoiceNote       = model.InvoiceNote;
            poco.LateCharge        = model.LateCharge;
            poco.LateChargeDays    = model.LateChargeDays;
            poco.IsConfirmed       = model.IsConfirmed;
            poco.UserID            = model.UserID;
            poco.LastUpdateTime    = model.LastUpdateTime;

            foreach (var d in poco.InvoicesDetails.ToList())
            {
                db.Delete(d);
                poco.InvoicesDetails.Remove(d);
            }

            foreach (var d in model.Details)
            {
                var det = new InvoicesDetail();
                det.InvoiceDetailDate          = d.InvoiceDetailDate;
                det.InvoiceDetailName          = d.InvoiceDetailName;
                det.InvoiceDetailTotalTime     = d.InvoiceDetailTotalTime;
                det.InvoiceDetailOverTime      = d.InvoiceDetailOverTime;
                det.InvoiceDetailRegularRate   = d.InvoiceDetailRegularRate;
                det.InvoiceDetailOverRate      = d.InvoiceDetailOverRate;
                det.InvoiceDetailRegularPay    = d.InvoiceDetailRegularPay;
                det.InvoiceDetailOvertimePay   = d.InvoiceDetailOvertimePay;
                det.InvoiceDetailGroupName     = d.InvoiceDetailGroupName;
                det.InvoiceDetailGroupPosition = d.InvoiceDetailGroupPosition;
                det.Invoice   = poco;
                det.InvoiceID = poco.InvoiceID;
                key.AddKey(det, d, d.GetName(p => p.InvoiceDetailID));
                poco.InvoicesDetails.Add(det);
                db.Add(det);
            }
        }
コード例 #9
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;
            }
        }
コード例 #10
0
        private static void InsertCompany(DSModel db, KeyBinder key, CompanyModel model)
        {
            Company poco = new Company();

            poco.CompanyID   = model.CompanyID;
            poco.CompanyName = model.CompanyName;
            if (model.CompanyCode == string.Empty)
            {
                poco.CompanyCode = "C" + CompanyRepository.PeekCompanyCode(db, "C");
            }
            else
            {
                poco.CompanyCode = model.CompanyCode;
            }
            poco.CompanyAddress1    = model.CompanyAddress1;
            poco.CompanyAddress2    = model.CompanyAddress2;
            poco.CompanyCity        = model.CompanyCity;
            poco.CompanyState       = model.CompanyState;
            poco.CompanyPostCode    = model.CompanyPostCode;
            poco.CompanyContactName = model.CompanyContactName;
            poco.CompanyFax         = model.CompanyFax;
            poco.CompanyPhone       = model.CompanyPhone;
            poco.CompanyEmail       = model.CompanyEmail;
            poco.LunchTime          = model.LunchTime;
            poco.TrainingTime       = model.TrainingTime;
            poco.IsEnabled          = model.IsEnabled;

            foreach (var loc in model.Locations)
            {
                Location l = LocationRepository.SaveLocation(db, key, loc, poco);
                poco.Locations.Add(l);
                key.AddKey(l, loc, loc.GetName(p => p.LocationID));
                key.AddKey(poco, loc, loc.GetName(p => p.CompanyID));
            }

            db.Add(poco);

            key.AddKey(poco, model, model.GetName(p => p.CompanyID));
        }
コード例 #11
0
        public static void SaveHolidays(DSModel db, KeyBinder key, List <HolidayModel> model)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var holidaysToDelete = db.Holidays.ToList();

            foreach (var h in holidaysToDelete.ToList())
            {
                var check = model.Where(hh => hh.HolidayDate == h.HolidayDate).FirstOrDefault();
                if (check == null)
                {
                    db.Delete(h);
                }
                else
                {
                    model.Remove(check);
                }
            }

            foreach (var h in model)
            {
                Holiday poco = new Holiday();
                poco.HolidayDate = h.HolidayDate;
                db.Add(poco);
                key.AddKey(poco, h, h.GetName(p => p.HolidayDate));
            }
        }
コード例 #12
0
        private static void InsertDispatch(DSModel db, KeyBinder key, DispatchModel model)
        {
            Dispatch poco = new Dispatch();

            poco.DriverID       = model.DriverID;
            poco.CompanyID      = model.CompanyID;
            poco.LocationID     = model.LocationID;
            poco.FromDateTime   = model.FromDateTime;
            poco.ToDateTime     = model.ToDateTime;
            poco.LunchTime      = model.LunchTime;
            poco.TrainingTime   = model.TrainingTime;
            poco.SpecialPayRate = model.SpecialPayRate;
            poco.MiscCharge     = model.MiscCharge;
            poco.Note           = model.Note;
            poco.IsCancelled    = model.IsCancelled;
            poco.IsConfirmed    = model.IsConfirmed;
            poco.HasLunch       = model.HasLunch;
            poco.HasTraining    = model.HasTraining;
            poco.UserID         = model.UserID;
            poco.LastUpdateTime = model.LastUpdateTime;
            db.Add(poco);
            key.AddKey(poco, model, model.GetName(p => p.DispatchID));
        }
コード例 #13
0
        private static void InsertDriver(DSModel db, KeyBinder key, DriverModel model)
        {
            Driver poco = new Driver();

            if (model.DriverCode == string.Empty)
            {
                poco.DriverCode = "D" + DriverRepository.PeekDriverCode(db, "D");
            }
            else
            {
                poco.DriverCode = model.DriverCode;
            }
            poco.FirstName       = model.FirstName;
            poco.SecondName      = model.SecondName;
            poco.LastName        = model.LastName;
            poco.DateOfBirth     = model.DateOfBirth;
            poco.DateOfHire      = model.DateOfHire;
            poco.CellPhone       = model.CellPhone;
            poco.EmergencyPhone  = model.EmergencyPhone;
            poco.Email           = model.Email;
            poco.PayRateOverride = model.PayRateOverride;
            poco.IsEnabled       = model.IsEnabled;
            foreach (var l in model.Locations)
            {
                poco.LocationsDrivers.Add(
                    new LocationsDriver()
                {
                    LocationID = l.LocationID,
                    Driver     = poco,
                    TravelPay  = l.TravelPay
                });
                key.AddKey(poco, l, poco.GetName(p => p.DriverID));
            }
            db.Add(poco);

            key.AddKey(poco, model, poco.GetName(p => p.DriverID));
        }