// Copy private async Task <ICollection <Models.Axapta> > FindAxaptaData() { var fetched = new List <AxaptaViewModels.AxaptaViewModel>(); var upload = new List <Models.Axapta>(); // Cars from kuras database var cars = await _kuras_context.Car.ToListAsync(); // Car details from axapta var dsAuto = await _context.DsAutoShort.ToListAsync(); // Card details from axapta var autoKort = await _context.DsAutoKort.ToListAsync(); //Employees in Axapta var empAx = await _context.Empltable.ToListAsync(); foreach (var auto in dsAuto) { // if car is not blocked // if employee id is not blank // if car is found in the kuras.Car table if (auto.Blocked == 0 && !String.IsNullOrWhiteSpace(auto.EmployeeId) && auto.Type != 2 && !auto.EmployeeId.Contains("ZZZZZZZZZ")) //&& FindCar(auto, cars)) { var found_emp = empAx.FirstOrDefault(x => x.Emplid == auto.EmployeeId); var found_kort = autoKort.FirstOrDefault(x => x.NumberPlate == auto.NumberPlate); fetched.Add(new AxaptaViewModels.AxaptaViewModel { AxEmployee = found_emp, DsAuto = auto, DsAutoKort = found_kort }); if (found_emp == null) { found_emp = new Empltable(); } if (found_kort == null) { found_kort = new DsAutoKort(); } upload.Add(new Models.Axapta { EmpIdAutoTable = auto.EmployeeId, MakeModel = auto.MakeModel, Type = auto.Type, Blocked = auto.Blocked, NumberPlate = auto.NumberPlate, CardNumber = found_kort.CardNumberShort, CardNumberD = found_kort.CardNumberD, EmpIdEmplTable = found_emp.Emplid, EmpName = found_emp.Name, EmpGroup = found_emp.Dimension, //group CityCode = found_emp.StateId, Occupation = found_emp.Title }); } } return(upload); }
// Searches for new data in axapta tables private async Task <ICollection <AxaptaViewModels.AxaptaViewModel> > FindNewAxaptaData() { var fetched = new List <AxaptaViewModels.AxaptaViewModel>(); var upload = new List <Models.Axapta>(); // Cars from kuras database var cars = await _kuras_context.Car.ToListAsync(); // Car details from axapta var dsAuto = await _context.DsAutoShort.ToListAsync(); // Card details from axapta var autoKort = await _context.DsAutoKort.ToListAsync(); //Employees in Axapta var empAx = await _context.Empltable.ToListAsync(); foreach (var auto in dsAuto) { // if car is not blocked // if employee id is not blank // if car is not found in the kuras.Car table if (auto.Blocked == 0 && !String.IsNullOrWhiteSpace(auto.EmployeeId) && auto.Type != 2 && !auto.EmployeeId.Contains("ZZZZZZZZZ") ) { if (!FindCar(auto, cars)) { // Searching for the same employee in empltable var found_emp = empAx.FirstOrDefault(x => x.Emplid == auto.EmployeeId); // Searching for the same numberPlate in autokort var found_kort = autoKort.FirstOrDefault(x => x.NumberPlate == auto.NumberPlate); // If none were found, create empty objects with no values if (found_emp == null) { found_emp = new Empltable(); } if (found_kort == null) { found_kort = new DsAutoKort(); } // For the index page (of Axapta) View fetched.Add(new AxaptaViewModels.AxaptaViewModel { AxEmployee = found_emp, DsAuto = auto, DsAutoKort = found_kort }); // Create an object which will be uploaded to Axapta table upload.Add(new Models.Axapta { EmpIdAutoTable = auto.EmployeeId, MakeModel = auto.MakeModel, Type = auto.Type, Blocked = auto.Blocked, NumberPlate = auto.NumberPlate, CardNumber = found_kort.CardNumberShort, CardNumberD = found_kort.CardNumberD, EmpIdEmplTable = found_emp.Emplid, EmpName = found_emp.Name, EmpGroup = found_emp.Dimension, //group CityCode = found_emp.StateId, Occupation = found_emp.Title }); } else { // if the car was found, we need to check if anything changed for it Models.Car fCar = null; FindCar(auto, cars, ref fCar); if (fCar != null) { string _model = null, _make = null; SeparateMakeModel(auto.MakeModel, ref _model, ref _make); // Change the existing Car if (_model.Trim(' ') != fCar.Model.Trim(' ')) { fCar.Model = _model.Trim(' '); } if (_make.Trim(' ') != fCar.Make.Trim(' ')) { fCar.Make = _make.Trim(' '); } // Save changes to the existing car _kuras_context.Update(fCar); await _kuras_context.SaveChangesAsync(); } } } } if (upload.Any()) { await UpdateTable(upload); } return(fetched); }