Ejemplo n.º 1
0
        public Task <GetDriverResponse> Get(int id)
        {
            var response = new GetDriverResponse();

            try
            {
                var driver    = _driverService.Get(id);
                var ids       = !string.IsNullOrEmpty(driver.VehicleTypeIDs) ? driver.VehicleTypeIDs.Split(',').ToList() : null;
                var cityEmpty = (driver.City + driver.Country + driver.District + driver.Street + driver.StreetNumber).Length;
                var address   = new
                {
                    City         = driver.City,
                    Country      = driver.Country,
                    District     = driver.District,
                    Street       = driver.Street,
                    StreetNumber = driver.StreetNumber
                };
                response.Data = new
                {
                    DriverInfo = new
                    {
                        Address = cityEmpty > 0 ? address : null,
                        driver.Code,
                        DoB = driver.DoB.HasValue ? driver.DoB.Value.ToString("dd/MM/yyyy", null) : "",
                        driver.IDCardNumber,
                        driver.Name,
                        driver.Note,
                        driver.PhoneNumber,
                        driver.Sex,
                        StartDate = driver.StartDate.HasValue ? driver.StartDate.Value.ToString("dd/MM/yyyy", null) : "",
                        driver.Status,
                        VehicleTypes = ids != null?_vehicleTypeService.GetByIds(ids.Select(int.Parse).ToList()) : new List <VehicleTypeReadModel>()
                    },
                    ID     = driver.ID,
                    UserID = driver.UserID
                };
                response.Message = "";
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Success = false;
            }
            return(Task.FromResult(response));
        }
Ejemplo n.º 2
0
        private async Task <GetDriverResponse> LoadDriver(Driver driver)
        {
            GetDriverResponse resp = new GetDriverResponse();

            var ethnicity = await repository.GetEthnicityTypeById(driver.EthnicityTypeId);

            DriverModel dm = new DriverModel()
            {
                CurrentPayPeriod            = new DateTime(2017, 11, 3),
                DateOfBirth                 = driver.DateOfBirth ?? DateTime.MinValue,
                DriverAccountingId          = driver.AccountingDriverId,
                DriverCity                  = driver.City,
                DriverFirstName             = driver.FirstName,
                DriverFullName              = driver.FirstName + ' ' + driver.LastName,
                DriverLastName              = driver.LastName,
                DriverLicenseExpirationDate = driver.DriverLicenseExpiration,
                DriverLicenseNumber         = driver.DriverLicenseNumber,
                DriverReportURL             = "http://www.google.com",
                DriverStateProvinceId       = driver.StateProvinceId ?? 0,
                DriverStateProvinceName     = (await repository.GetStateProvinceById(driver.StateProvinceId ?? 0))?.StateProvinceName ?? "",
                DriverStreetAddressLine1    = driver.StreetAddressLine1,
                DriverStreetAddressLine2    = driver.StreetAddressLine2,
                DriverZip         = driver.Zip,
                EthnicityID       = "",
                GenderID          = driver.GenderTypeId ?? 0,
                HireDate          = driver.HireDate ?? DateTime.MinValue,
                IsActive          = driver.IsActive ?? false,
                TermDate          = driver.TermDate,
                DriverId          = driver.DriverId,
                EthnicityTypeId   = ethnicity.EthnicityTypeId,
                EthnicityTypeName = ethnicity.EthnicityTypeName,
                IsMinority        = ethnicity.IsMinority
            };

            resp.CurrentDriver = dm;

            //setup the multiple rows of dataas well
            var contracts = await repository.GetDriverContractsByDriverId(driver.DriverId);

            foreach (DriverContract dc in contracts)
            {
                resp.CurrentDriver.DriverContracts.Add(new DriverContractModel
                {
                    DriverContractEndDate   = dc.Contract.ContractEndDate ?? DateTime.MinValue,
                    DriverContractID        = dc.DriverContractId,
                    DriverContractName      = dc.Contract.ContractName,
                    DriverContractNumber    = dc.Contract.ContractNumber,
                    DriverContractStartDate = dc.Contract.ContractStartDate,
                    DriverID = dc.DriverId
                });
            }

            var emails = await repository.GetDriverEmailsByDriverId(driver.DriverId);

            foreach (DriverEmail de in emails)
            {
                resp.CurrentDriver.DriverEmails.Add(new DriverEmailModel
                {
                    DriverEmailAddress   = de.DriverEmailAddress,
                    DriverEmailAddressID = de.DriverEmailId,
                    DriverID             = de.DriverId,
                    IsPrimary            = de.IsPrimary
                });
            }

            var meds = await repository.GetDriverMedicalHistoryByDriverId(driver.DriverId);

            foreach (DriverMedicalHistory med in meds)
            {
                resp.CurrentDriver.DriverMedicalEvaluations.Add(new DriverMedicalEvaluationModel
                {
                    DriverID = med.DriverId,
                    DriverMedicalEffectiveDate  = med.MedicalExamEffectiveDate,
                    DriverMedicalEvaluationID   = med.DriverMedicalHistoryId,
                    DriverMedicalExpirationDate = med.MedicalExamExpirationDate,
                    DriverMedicalProviderID     = med.MedicalProviderId,
                    DriverMedicalProviderName   = med.MedicalProvider.MedicalProviderName,
                    DriverMedicalProviderRate   = med.MedicalExamRate
                });
            }

            var phones = await repository.GetDriverPhonesByDriverId(driver.DriverId);

            foreach (DriverPhone phone in phones)
            {
                resp.CurrentDriver.DriverPhones.Add(new DriverPhoneModel
                {
                    DriverID          = phone.DriverId,
                    DriverPhoneID     = phone.DriverPhoneId,
                    DriverPhoneNumber = phone.DriverPhoneNumber,
                    DriverPhoneTypeID = phone.PhoneNumberTypeId,
                    IsPrimary         = phone.IsPrimary
                });
            }

            var insurances = await repository.GetDriverInsuranceByDriverId(driver.DriverId);

            foreach (DriverInsurance insurance in insurances)
            {
                resp.CurrentDriver.DriverInsurances.Add(new DriverInsuranceModel
                {
                    DriverID = insurance.DriverId,
                    DriverInsuranceEndDate       = insurance.InsuranceEndDate ?? DateTime.MinValue,
                    DriverInsuranceID            = insurance.DriverInsuranceId,
                    DriverInsuranceProviderID    = insurance.InsuranceProviderId,
                    DriverInsuranceProviderRate  = insurance.InsuranceRate,
                    DriverInsuranceStartDate     = insurance.InsuranceEffectiveDate,
                    DriverInsureanceProviderName = insurance.InsuranceProvider.InsuranceProviderName
                });
            }


            //get the recent info from the retrieved
            var recentInsurance = resp.CurrentDriver.DriverInsurances.OrderByDescending(i => i.DriverInsuranceStartDate).FirstOrDefault();

            if (recentInsurance != null)
            {
                resp.CurrentDriver.RecentDriverInsurancePolicyURL     = "www.yahoo.com";
                resp.CurrentDriver.RecentDriverInsuranceProviderId    = recentInsurance.DriverInsuranceProviderID;
                resp.CurrentDriver.RecentDriverInsuranceProviderRate  = recentInsurance.DriverInsuranceProviderRate;
                resp.CurrentDriver.RecentDriverInsureanceProviderName = recentInsurance.DriverInsureanceProviderName;
            }

            var recentMedEval = resp.CurrentDriver.DriverMedicalEvaluations.OrderByDescending(m => m.DriverMedicalEffectiveDate).FirstOrDefault();

            if (recentMedEval != null)
            {
                resp.CurrentDriver.RecentDriverEvaluationDate        = recentMedEval.DriverMedicalEffectiveDate;
                resp.CurrentDriver.RecentDriverMedicalExpirationDate = recentMedEval.DriverMedicalExpirationDate;
            }

            return(resp);
        }