public void UpdateDriverLicenseDetail(DriverLicenseUpdateViewModel data) { if (data.PlanI == 1) { // insert to DriverLicenseUpdate_D table var driverLicenceInsert = Mapper.Map <DriverLicenseUpdateViewModel, DriverLicenseUpdate_D>(data); _driverLicenseUpdateRepository.Add(driverLicenceInsert); } else { // update DriverLicenseUpdate_D var driverLicenceUpdate = Mapper.Map <DriverLicenseUpdateViewModel, DriverLicenseUpdate_D>(data); var driverLicenceDelete = _driverLicenseUpdateRepository.Query(d => d.DriverC == data.DriverC && d.LicenseC == data.LicenseC && d.ExpiryD == data.ExpiryD).FirstOrDefault(); _driverLicenseUpdateRepository.Delete(driverLicenceDelete); _driverLicenseUpdateRepository.Add(driverLicenceUpdate); } // update to DriverLicense_M table var driverC = data.DriverC; var licenseC = data.LicenseC; var driverLicense = _driverLicenseRepository.Query(d => d.DriverC == driverC && d.LicenseC == licenseC).FirstOrDefault(); if (driverLicense != null) { driverLicense.ExpiryD = data.NextExpiryD; _driverLicenseRepository.Update(driverLicense); } SaveDriverLicense(); }
public DriverLicenseUpdateViewModel GetDriverLicenseUpdateDetail(string driverC, string licenseC, DateTime updateD, int planI) { var result = new DriverLicenseUpdateViewModel(); var updateDMax = _driverLicenseUpdateRepository.Query(d => d.DriverC == driverC && d.LicenseC == licenseC).OrderBy("UpdateD desc").FirstOrDefault(); var driverLicenseUpdate = from a in _driverLicenseUpdateRepository.GetAllQueryable() join b in _driverRepository.GetAllQueryable() on a.DriverC equals b.DriverC join c in _licenseRepository.GetAllQueryable() on a.LicenseC equals c.LicenseC where (a.DriverC == driverC && a.LicenseC == licenseC && a.UpdateD == updateD ) select new DriverLicenseUpdateViewModel() { DriverC = a.DriverC, DriverN = b != null ? b.LastN + " " + b.FirstN : "", LicenseC = a.LicenseC, LicenseN = c != null ? c.LicenseN : "", ExpiryD = a.ExpiryD, UpdateD = a.UpdateD, NextExpiryD = a.NextExpiryD }; if (planI == 1) { if (!driverLicenseUpdate.Any()) { var driverLicenseeList = (from a in _driverLicenseRepository.GetAllQueryable() join b in _driverRepository.GetAllQueryable() on a.DriverC equals b.DriverC join c in _licenseRepository.GetAllQueryable() on a.LicenseC equals c.LicenseC where (a.DriverC == driverC && a.LicenseC == licenseC ) select new DriverLicenseViewModel() { DriverC = a.DriverC, DriverN = b != null ? b.LastN + " " + b.FirstN : "", LicenseC = a.LicenseC, LicenseN = c != null ? c.LicenseN : "", ExpiryD = a.ExpiryD, }).ToList(); result.DriverC = driverLicenseeList[0].DriverC; result.DriverN = driverLicenseeList[0].DriverN; result.LicenseC = driverLicenseeList[0].LicenseC; result.LicenseN = driverLicenseeList[0].LicenseN; result.ExpiryD = driverLicenseeList[0].ExpiryD != null ? (DateTime)driverLicenseeList[0].ExpiryD : DateTime.MinValue; result.UpdateD = updateD; result.IsDisableNextExpiryD = false; result.IsInsert = true; result.IsDelete = false; } else { var driverLicenseUpdateList = driverLicenseUpdate.ToList(); result.DriverC = driverLicenseUpdateList[0].DriverC; result.DriverN = driverLicenseUpdateList[0].DriverN; result.LicenseC = driverLicenseUpdateList[0].LicenseC; result.LicenseN = driverLicenseUpdateList[0].LicenseN; result.ExpiryD = driverLicenseUpdateList[0].NextExpiryD; result.UpdateD = updateD; result.IsDisableNextExpiryD = false; result.IsInsert = true; result.IsDelete = false; } } else { if (updateDMax != null) { var driverLicenseUpdateList = driverLicenseUpdate.ToList(); result.DriverC = driverLicenseUpdateList[0].DriverC; result.DriverN = driverLicenseUpdateList[0].DriverN; result.LicenseC = driverLicenseUpdateList[0].LicenseC; result.LicenseN = driverLicenseUpdateList[0].LicenseN; result.ExpiryD = driverLicenseUpdateList[0].ExpiryD; result.UpdateD = updateD; result.NextExpiryD = driverLicenseUpdateList[0].NextExpiryD; if (driverLicenseUpdateList[0].UpdateD == updateDMax.UpdateD) { result.IsDisableNextExpiryD = false; result.IsInsert = true; result.IsDelete = true; } else { result.IsDisableNextExpiryD = true; result.IsInsert = false; result.IsDelete = false; } } } return(result); }
public void UpdateDriverLicenseDetail(DriverLicenseUpdateViewModel data) { _driverLicenseService.UpdateDriverLicenseDetail(data); }