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 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);
        }
Пример #3
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);
        }
Пример #4
0
        private static void SaveReminders(DSModel db, KeyBinder key, DriverMedicalModel model, DriversMedical poco)
        {
            string sqlDelete = @"DELETE FROM drivers_medicals_reminders WHERE DriverMedicalID = @DriverMedicalID AND DriverMedicalReminderID NOT IN (@DriverMedicalReminderID);";
            string ids       = "0";

            if (model.Reminders.Count > 0)
            {
                ids = string.Join <uint>(",", model.Reminders.Select(r => r.DriverMedicalReminderID));
            }

            sqlDelete = sqlDelete.Replace("@DriverMedicalReminderID", ids);

            db.ExecuteNonQuery(sqlDelete, new MySqlParameter("DriverMedicalID", poco.DriverMedicalID));
            string sqlInsert = @"
                INSERT INTO drivers_medicals_reminders
                  (DriverMedicalID, ReminderID, ReminderType, ShouldRemind) VALUES (@DriverMedicalID, @ReminderID, @ReminderType, @ShouldRemind);
                SELECT LAST_INSERT_ID();";
            string sqlUpdate = @"
                UPDATE drivers_medicals_reminders
                SET
                  DriverMedicalID = @DriverMedicalID, 
                  ReminderID = @ReminderID, 
                  ReminderType = @ReminderType, 
                  ShouldRemind = @ShouldRemind
                WHERE
                  DriverMedicalReminderID = @DriverMedicalReminderID;";

            foreach (var rem in model.Reminders)
            {
                if (rem.DriverMedicalReminderID == 0)
                {
                    rem.DriverMedicalID = poco.DriverMedicalID;
                    UtilityModel <uint> temp = new UtilityModel <uint>();
                    temp.Value = db.ExecuteQuery <uint>(sqlInsert,
                                                        new MySqlParameter("DriverMedicalID", rem.DriverMedicalID),
                                                        new MySqlParameter("ReminderID", rem.ReminderID),
                                                        new MySqlParameter("ReminderType", rem.ReminderType),
                                                        new MySqlParameter("ShouldRemind", rem.ShouldRemind))
                                 .First();
                    key.AddKey(temp, rem, "Value", rem.GetName(p => p.DriverMedicalReminderID));
                }
                else
                {
                    rem.DriverMedicalID = poco.DriverMedicalID;
                    db.ExecuteNonQuery(sqlUpdate,
                                       new MySqlParameter("DriverMedicalReminderID", rem.DriverMedicalReminderID),
                                       new MySqlParameter("DriverMedicalID", rem.DriverMedicalID),
                                       new MySqlParameter("ReminderID", rem.ReminderID),
                                       new MySqlParameter("ReminderType", rem.ReminderType),
                                       new MySqlParameter("ShouldRemind", rem.ShouldRemind));
                }
            }
        }
Пример #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);
        }
        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);
            }
        }
        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);
        }
Пример #8
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));
        }
Пример #9
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);
        }
Пример #10
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));
        }
        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);
            }
        }
Пример #12
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;
            }
        }
        private static Location UpdateLocation(DSModel db, KeyBinder key, LocationModel model, Company company = null)
        {
            var poco = db.Locations.Where(l => l.LocationID == model.LocationID).FirstOrDefault();

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

            poco.LocationName = model.LocationName;
            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;
            return(poco);
        }
Пример #14
0
        private static void UpdateCompany(DSModel db, KeyBinder key, CompanyModel model)
        {
            Company poco = db.Companies.Where(c => c.CompanyID == model.CompanyID).FirstOrDefault();

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

            poco.CompanyID          = model.CompanyID;
            poco.CompanyName        = model.CompanyName;
            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;

            List <Location> locationsToBeDeleted = poco.Locations.Where(dl => !model.Locations.Any(ml => ml.LocationID == dl.LocationID)).ToList();

            foreach (var del in locationsToBeDeleted)
            {
                db.Delete(del);
                poco.Locations.Remove(del);
            }

            foreach (var ins in model.Locations)
            {
                Location loc = LocationRepository.SaveLocation(db, key, ins, poco);
                poco.Locations.Add(loc);
                key.AddKey(loc, ins, ins.GetName(p => p.LocationID));
            }
        }
Пример #15
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));
            }
        }
Пример #16
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));
        }