public bool SaveDriverServices(int driverProfileID, DriverInterviewProfileEntity driverInterviewProfile, List <DriverServiceEntity> driverServices)
        {
            bool isDriverProfileSaved = false;
            DriverInterviewProfile driverInterviewProfiledb = new DriverInterviewProfile();

            driverInterviewProfiledb.Class             = driverInterviewProfile.Class;
            driverInterviewProfiledb.Date              = driverInterviewProfile.Date;
            driverInterviewProfiledb.DOB               = driverInterviewProfile.DOB;
            driverInterviewProfiledb.DriverInterviewID = driverInterviewProfile.DriverInterviewID;
            driverInterviewProfiledb.DriverName        = driverInterviewProfile.DriverName;
            driverInterviewProfiledb.OrderFormID       = driverProfileID;
            driverInterviewProfiledb.EIN               = driverInterviewProfile.EIN;
            driverInterviewProfiledb.Email             = driverInterviewProfile.Email;
            driverInterviewProfiledb.ExpirationDate    = driverInterviewProfile.ExpirationDate;
            driverInterviewProfiledb.LegalName         = driverInterviewProfile.LegalName;
            driverInterviewProfiledb.LicenseNo         = driverInterviewProfile.LicenseNo;
            driverInterviewProfiledb.Notes             = driverInterviewProfile.Notes;
            driverInterviewProfiledb.Phone             = driverInterviewProfile.Phone;
            driverInterviewProfiledb.SSN               = driverInterviewProfile.SSN;
            driverInterviewProfiledb.StatusIssued      = driverInterviewProfile.StatusIssued;
            driverInterviewProfiledb.Supervisor        = driverInterviewProfile.Supervisor;
            driverInterviewProfiledb.USDOT             = driverInterviewProfile.USDOT;
            uow.DriverInterviewProfileRepository.Insert(driverInterviewProfiledb);
            uow.Save();

            foreach (DriverServiceEntity driverService in driverServices)
            {
                DriverService driverServicedb = new DriverService();
                driverServicedb.DriverInterviewProfileID = driverInterviewProfiledb.DriverInterviewID;
                driverServicedb.ServiceID = driverService.ServiceID;
                uow.DriverServiceRepository.Insert(driverServicedb);
                uow.Save();
            }

            return(isDriverProfileSaved);
        }
        public bool EditDriverProfile(int driverProfileID, ProfileCardEntity profileCard, OrderFormEntity orderForm, List <DriverInterviewProfileEntity> driverInterviewProfiles, bool isSubmitted, List <DriverServiceEntity> driverServices)
        {
            bool isDriverProfileEdited = false;

            using (uow = new UnitOfWork.UnitOfWork())
            {
                try
                {
                    OrderForm orderFormdb = uow.OrderFormRepository.Get().Where(x => x.OrderFormID == driverProfileID).FirstOrDefault();
                    orderFormdb.PhysicalAddress = orderForm.PhysicalAddress;
                    orderFormdb.BillingAddress  = orderForm.BillingAddress;
                    orderFormdb.CA = orderForm.CA;
                    orderFormdb.ComplianceSupervisor = orderForm.ComplianceSupervisor;
                    orderFormdb.DateTime             = Helper.DateTimeJavaScript.GetCurrentTime().ToString();
                    orderFormdb.DBA                 = orderForm.DBA;
                    orderFormdb.LegalName           = orderForm.LegalName;
                    orderFormdb.Name                = orderForm.Name;
                    orderFormdb.Email               = orderForm.Email;
                    orderFormdb.NameOnCard          = orderForm.NameOnCard;
                    orderFormdb.USDot               = orderForm.USDot;
                    orderFormdb.DriverPhone         = orderForm.DriverPhone;
                    orderFormdb.CompanyType         = orderForm.CompanyType;
                    orderFormdb.IsSubmitted         = orderForm.IsSubmitted;
                    orderFormdb.DOTPinNo            = orderForm.DOTPinNo;
                    orderFormdb.ComplianceUserID    = orderForm.ComplianceUserID;
                    orderFormdb.AdditionalPhoneNo   = orderForm.AdditionalPhoneNo;
                    orderFormdb.AdditionalPhoneType = orderForm.AdditionalPhoneType;
                    uow.OrderFormRepository.Update(orderFormdb);
                    uow.Save();

                    ProfileCard profileCarddb = uow.ProfileCardRepository.Get().Where(x => x.OrderFormID == driverProfileID).FirstOrDefault();
                    profileCarddb.CardType    = profileCard.CardType;
                    profileCarddb.CorDC       = profileCard.CorDC;
                    profileCarddb.CVC         = profileCard.CVC;
                    profileCarddb.OrderFormID = orderFormdb.OrderFormID;
                    profileCarddb.Expiration  = profileCard.Expiration;
                    profileCarddb.IsSubmitted = profileCard.IsSubmitted;
                    uow.ProfileCardRepository.Update(profileCarddb);
                    uow.Save();

                    List <DriverService> usDotServiceTemp = uow.DriverServiceRepository.Get().Where(x => x.DriverInterviewProfileID == orderFormdb.OrderFormID).ToList();
                    foreach (DriverService service in usDotServiceTemp)
                    {
                        uow.DriverServiceRepository.Delete(service);
                        uow.Save();
                    }

                    if (driverServices != null)
                    {
                        foreach (DriverServiceEntity driverService in driverServices)
                        {
                            DriverService driverServicedb = new DriverService();
                            driverServicedb.DriverInterviewProfileID = orderFormdb.OrderFormID;
                            driverServicedb.ServiceID = driverService.ServiceID;
                            uow.DriverServiceRepository.Insert(driverServicedb);
                            uow.Save();
                        }
                    }

                    List <DriverInterviewProfile> usDotDriverInterviewProfileTemp = uow.DriverInterviewProfileRepository.Get().Where(x => x.OrderFormID == driverProfileID).ToList();
                    foreach (DriverInterviewProfile item in usDotDriverInterviewProfileTemp)
                    {
                        List <DriverVehicleCargo> usDotVehicleCargoTemp = uow.DriverVehicleCargoRepository.Get().Where(x => x.DriverVehicleID == item.DriverInterviewID).ToList();
                        foreach (DriverVehicleCargo vehicleCargo in usDotVehicleCargoTemp)
                        {
                            uow.DriverVehicleCargoRepository.Delete(vehicleCargo);
                            uow.Save();
                        }

                        List <DriverVehicle> usDotVehicleTemp = uow.DriverVehicleRepository.Get().Where(x => x.OrderFormID == item.DriverInterviewID).ToList();
                        foreach (DriverVehicle vehicleCargo in usDotVehicleTemp)
                        {
                            uow.DriverVehicleRepository.Delete(vehicleCargo);
                            uow.Save();
                        }

                        uow.DriverInterviewProfileRepository.Delete(item);
                        uow.Save();
                    }

                    foreach (DriverInterviewProfileEntity driverInterviewProfile in driverInterviewProfiles)
                    {
                        DriverInterviewProfile driverInterviewProfiledb = new DriverInterviewProfile();
                        driverInterviewProfiledb.Class          = driverInterviewProfile.Class;
                        driverInterviewProfiledb.Date           = driverInterviewProfile.Date;
                        driverInterviewProfiledb.DOB            = driverInterviewProfile.DOB;
                        driverInterviewProfiledb.DriverName     = driverInterviewProfile.DriverName;
                        driverInterviewProfiledb.OrderFormID    = orderFormdb.OrderFormID;
                        driverInterviewProfiledb.EIN            = driverInterviewProfile.EIN;
                        driverInterviewProfiledb.Email          = driverInterviewProfile.Email;
                        driverInterviewProfiledb.ExpirationDate = driverInterviewProfile.ExpirationDate;
                        driverInterviewProfiledb.LegalName      = driverInterviewProfile.LegalName;
                        driverInterviewProfiledb.LicenseNo      = driverInterviewProfile.LicenseNo;
                        driverInterviewProfiledb.Notes          = driverInterviewProfile.Notes;
                        driverInterviewProfiledb.Phone          = driverInterviewProfile.Phone;
                        driverInterviewProfiledb.SSN            = driverInterviewProfile.SSN;
                        driverInterviewProfiledb.StatusIssued   = driverInterviewProfile.StatusIssued;
                        driverInterviewProfiledb.Supervisor     = driverInterviewProfile.Supervisor;
                        driverInterviewProfiledb.USDOT          = driverInterviewProfile.USDOT;
                        driverInterviewProfiledb.CDLNonCDL      = driverInterviewProfile.CDLNonCDL;
                        driverInterviewProfiledb.IsSubmitted    = driverInterviewProfile.IsSubmitted;
                        uow.DriverInterviewProfileRepository.Insert(driverInterviewProfiledb);
                        uow.Save();

                        if (driverInterviewProfile.DriverCargos != null)
                        {
                            foreach (DriverVehicleCargoEntity drivercargo in driverInterviewProfile.DriverCargos)
                            {
                                DriverVehicleCargo driverVehicleCargodb = new DriverVehicleCargo();
                                driverVehicleCargodb.DriverVehicleID  = driverInterviewProfiledb.DriverInterviewID;
                                driverVehicleCargodb.CargoCarriedName = drivercargo.CargoCarriedName;
                                uow.DriverVehicleCargoRepository.Insert(driverVehicleCargodb);
                                uow.Save();
                            }
                        }

                        DriverVehicle driverVehicledb = new DriverVehicle();
                        driverVehicledb.OrderFormID       = driverInterviewProfiledb.DriverInterviewID;
                        driverVehicledb.DriverVehicleInfo = driverInterviewProfile.DriverVehicle.DriverVehicleInfo;
                        driverVehicledb.GVW   = driverInterviewProfile.DriverVehicle.GVW;
                        driverVehicledb.Make  = driverInterviewProfile.DriverVehicle.Make;
                        driverVehicledb.Model = driverInterviewProfile.DriverVehicle.Model;
                        driverVehicledb.Year  = driverInterviewProfile.DriverVehicle.Year;
                        uow.DriverVehicleRepository.Insert(driverVehicledb);
                        uow.Save();
                    }

                    isDriverProfileEdited = true;
                }
                catch
                {
                    isDriverProfileEdited = false;
                }
            }


            return(isDriverProfileEdited);
        }
        public int AddDriverProfile(ProfileCardEntity profileCard, OrderFormEntity orderForm, List <DriverInterviewProfileEntity> driverInterviewProfiles, List <DriverServiceEntity> driverServices)
        {
            int driverProfileID = 0;

            using (uow = new UnitOfWork.UnitOfWork())
            {
                try
                {
                    OrderForm orderFormdb = new OrderForm();
                    orderFormdb.PhysicalAddress = orderForm.PhysicalAddress;
                    orderFormdb.BillingAddress  = orderForm.BillingAddress;
                    orderFormdb.CA = orderForm.CA;
                    orderFormdb.ComplianceSupervisor = orderForm.ComplianceSupervisor;
                    orderFormdb.DateTime             = Helper.DateTimeJavaScript.GetCurrentTime().ToString();
                    orderFormdb.DBA                 = orderForm.DBA;
                    orderFormdb.LegalName           = orderForm.LegalName;
                    orderFormdb.Name                = orderForm.Name;
                    orderFormdb.Email               = orderForm.Email;
                    orderFormdb.NameOnCard          = orderForm.NameOnCard;
                    orderFormdb.OrderFormID         = orderForm.OrderFormID;
                    orderFormdb.USDot               = orderForm.USDot;
                    orderFormdb.DriverPhone         = orderForm.DriverPhone;
                    orderFormdb.CompanyType         = orderForm.CompanyType;
                    orderFormdb.IsSubmitted         = orderForm.IsSubmitted;
                    orderFormdb.ComplianceUserID    = orderForm.ComplianceUserID;
                    orderFormdb.SaleID              = orderForm.SaleID;
                    orderFormdb.DOTPinNo            = orderForm.DOTPinNo;
                    orderFormdb.AdditionalPhoneNo   = orderForm.AdditionalPhoneNo;
                    orderFormdb.AdditionalPhoneType = orderForm.AdditionalPhoneType;
                    uow.OrderFormRepository.Insert(orderFormdb);
                    uow.Save();

                    ProfileCard profileCarddb = new ProfileCard();
                    profileCarddb.CardType        = profileCard.CardType;
                    profileCarddb.CorDC           = profileCard.CorDC;
                    profileCarddb.CVC             = profileCard.CVC;
                    profileCarddb.OrderFormID     = orderFormdb.OrderFormID;
                    profileCarddb.Expiration      = profileCard.Expiration;
                    profileCarddb.ProfileCardInfo = profileCard.ProfileCardInfo;
                    profileCarddb.IsSubmitted     = profileCard.IsSubmitted;
                    uow.ProfileCardRepository.Insert(profileCarddb);
                    uow.Save();

                    foreach (DriverServiceEntity driverService in driverServices)
                    {
                        DriverService driverServicedb = new DriverService();
                        driverServicedb.DriverInterviewProfileID = orderFormdb.OrderFormID;
                        driverServicedb.ServiceID = driverService.ServiceID;
                        uow.DriverServiceRepository.Insert(driverServicedb);
                        uow.Save();
                    }

                    foreach (DriverInterviewProfileEntity driverInterviewProfile in driverInterviewProfiles)
                    {
                        DriverInterviewProfile driverInterviewProfiledb = new DriverInterviewProfile();
                        driverInterviewProfiledb.Class          = driverInterviewProfile.Class;
                        driverInterviewProfiledb.Date           = driverInterviewProfile.Date;
                        driverInterviewProfiledb.DOB            = driverInterviewProfile.DOB;
                        driverInterviewProfiledb.DriverName     = driverInterviewProfile.DriverName;
                        driverInterviewProfiledb.OrderFormID    = orderFormdb.OrderFormID;
                        driverInterviewProfiledb.EIN            = driverInterviewProfile.EIN;
                        driverInterviewProfiledb.Email          = driverInterviewProfile.Email;
                        driverInterviewProfiledb.ExpirationDate = driverInterviewProfile.ExpirationDate;
                        driverInterviewProfiledb.LegalName      = driverInterviewProfile.LegalName;
                        driverInterviewProfiledb.LicenseNo      = driverInterviewProfile.LicenseNo;
                        driverInterviewProfiledb.Notes          = driverInterviewProfile.Notes;
                        driverInterviewProfiledb.Phone          = driverInterviewProfile.Phone;
                        driverInterviewProfiledb.SSN            = driverInterviewProfile.SSN;
                        driverInterviewProfiledb.StatusIssued   = driverInterviewProfile.StatusIssued;
                        driverInterviewProfiledb.Supervisor     = driverInterviewProfile.Supervisor;
                        driverInterviewProfiledb.USDOT          = driverInterviewProfile.USDOT;
                        driverInterviewProfiledb.CDLNonCDL      = driverInterviewProfile.CDLNonCDL;
                        driverInterviewProfiledb.IsSubmitted    = driverInterviewProfile.IsSubmitted;
                        uow.DriverInterviewProfileRepository.Insert(driverInterviewProfiledb);
                        uow.Save();



                        foreach (DriverVehicleCargoEntity drivercargo in driverInterviewProfile.DriverCargos)
                        {
                            DriverVehicleCargo driverVehicleCargodb = new DriverVehicleCargo();
                            driverVehicleCargodb.DriverVehicleID  = driverInterviewProfiledb.DriverInterviewID;
                            driverVehicleCargodb.CargoCarriedName = drivercargo.CargoCarriedName;
                            uow.DriverVehicleCargoRepository.Insert(driverVehicleCargodb);
                            uow.Save();
                        }


                        DriverVehicle driverVehicledb = new DriverVehicle();
                        driverVehicledb.OrderFormID       = driverInterviewProfiledb.DriverInterviewID;
                        driverVehicledb.DriverVehicleInfo = driverInterviewProfile.DriverVehicle.DriverVehicleInfo;
                        driverVehicledb.GVW   = driverInterviewProfile.DriverVehicle.GVW;
                        driverVehicledb.Make  = driverInterviewProfile.DriverVehicle.Make;
                        driverVehicledb.Model = driverInterviewProfile.DriverVehicle.Model;
                        driverVehicledb.Year  = driverInterviewProfile.DriverVehicle.Year;
                        uow.DriverVehicleRepository.Insert(driverVehicledb);
                        uow.Save();
                    }
                }
                catch
                {
                    driverProfileID = 0;
                }
            }

            return(driverProfileID);
        }