Пример #1
0
        public void DeleteDriver(string id)
        {
            var driverToRemove = _driverRepository.Get(c => c.DriverC == id);

            if (driverToRemove != null)
            {
                _driverRepository.Delete(driverToRemove);

                var deleteItem = _driverLicenseRepository.Query(x => x.DriverC == id);
                if (deleteItem.Any())
                {
                    foreach (DriverLicense_M item in deleteItem)
                    {
                        _driverLicenseRepository.Delete(item);
                    }
                }

                SaveDriver();
            }
        }
Пример #2
0
        public void UpdateDriverLicenses(List <DriverLicenseViewModel> newLicenseList)
        {
            if (newLicenseList.Count == 0)
            {
                return;
            }

            var oldLicenseList = _driverLicenseRepository.GetAll().Where(x => x.DriverC == newLicenseList[0].DriverC);

            //xoa
            foreach (var item in oldLicenseList)
            {
                if (newLicenseList.Any(x => x.DriverC == item.DriverC && x.LicenseC == item.LicenseC) == false)
                {
                    _driverLicenseRepository.Delete(item);
                }
            }
            //update
            foreach (var item in newLicenseList)
            {
                if (oldLicenseList.Any(x => x.DriverC == item.DriverC && x.LicenseC == item.LicenseC) == false)
                {
                    var addItem = Mapper.Map <DriverLicenseViewModel, DriverLicense_M>(item);
                    _driverLicenseRepository.Add(addItem);
                }
                else
                {
                    var updateDriver = oldLicenseList.Where(x => x.DriverC == item.DriverC && x.LicenseC == item.LicenseC).FirstOrDefault();
                    if (updateDriver != null)
                    {
                        updateDriver.DriverLicenseD  = item.DriverLicenseD;
                        updateDriver.DriverLicenseNo = item.DriverLicenseNo;
                        updateDriver.ExpiryD         = item.ExpiryD;
                        _driverLicenseRepository.Update(updateDriver);
                    }
                }
            }

            SaveDriverLicense();
        }