public ObservableCollection <MaintenanceCycleModel> GetAll() { ObservableCollection <MaintenanceCycleModel> maintenanceCycleModels = new ObservableCollection <MaintenanceCycleModel>(); foreach (MaintenanceCycle cycle in dataBase.MaintenanceCycles.GetAll()) { MaintenanceCycleModel maintenanceCycleModel = Get(cycle); maintenanceCycleModels.Add(maintenanceCycleModel); } return(maintenanceCycleModels); }
public void Update(MaintenanceCycleModel maintenanceCycleModel) { MaintenanceCycle maintenanceCycle = new MaintenanceCycle(); MaintenanceCycle oldMaintenanceCycle = dataBase.MaintenanceCycles.Read(maintenanceCycleModel.MaintenanceCycleId); MaintenanceYear maintenanceYear; List <MaintenanceType> maintenanceTypes = new List <MaintenanceType>(dataBase.MaintenanceTypes.GetAll()); while (oldMaintenanceCycle.MaintenanceYears.Count != 0) { dataBase.MaintenanceYears.Delete(oldMaintenanceCycle.MaintenanceYears.First()); } dataBase.Save(); oldMaintenanceCycle.Name = maintenanceCycleModel.Name; oldMaintenanceCycle.ShowName = maintenanceCycleModel.ShowName; for (int i = 0; i < maintenanceCycleModel.MaintenanceTypes.Length; i++) { if (maintenanceCycleModel.MaintenanceTypes[i] != null) { maintenanceYear = new MaintenanceYear(); maintenanceYear.Year = i; maintenanceYear.MaintenanceType = maintenanceTypes.First(x => x.Name == maintenanceCycleModel.MaintenanceTypes[i]); maintenanceYear.MaintenanceCycle = oldMaintenanceCycle; dataBase.MaintenanceYears.Create(maintenanceYear); } } //dataBase.MaintenanceCycles.Update(maintenanceCycle); dataBase.Save(); maintenanceCycle = dataBase.MaintenanceCycles.Read(oldMaintenanceCycle.MaintenanceCycleId); List <MaintainedEquipmentByCycle> maintainedEquipmentsByCycle = GetAllMaintainedEquipments(maintenanceCycle.MaintenanceCycleId); if (maintainedEquipmentsByCycle.Count != 0) { foreach (MaintainedEquipmentByCycle equipment in maintainedEquipmentsByCycle) { if (equipment is Device) { BaseDeviceService deviceService = new BaseDeviceService(dataBase); deviceService.UpdateRecords(maintenanceCycle, (Device)equipment); } else if (equipment is AdditionalWork) { AdditionalWorkService combineDeviceService = new AdditionalWorkService(dataBase); combineDeviceService.UpdateRecords(maintenanceCycle, (AdditionalWork)equipment); } } dataBase.Save(); } }
public MaintenanceCycleViewModel(IServiceUnitOfWork serviceUnitOfWork, MaintenanceCycleModel maintenanceCycleModel, ActionType actionType) { this.actionType = actionType; this.serviceUnitOfWork = serviceUnitOfWork; oldMaitenanceCycleModel = maintenanceCycleModel; MaintenanceTypes = serviceUnitOfWork.MaintenanceTypes.GetAll(); MaintenanceTypes.Insert(0, new MaintenanceType()); MaintenanceCycleModel cycle = new MaintenanceCycleModel(); cycle.Name = maintenanceCycleModel.Name; cycle.ShowName = maintenanceCycleModel.ShowName; for (int i = 0; i < cycle.MaintenanceTypes.Length; i++) { cycle.MaintenanceTypes[i] = maintenanceCycleModel.MaintenanceTypes[i]; } MaintenanceCycleModel = cycle; }
public MaintenanceCycleModel Get(MaintenanceCycle maintenanceCycle) { MaintenanceCycle cycle = dataBase.MaintenanceCycles.Read(maintenanceCycle.MaintenanceCycleId); MaintenanceCycleModel maintenanceCycleModel = new MaintenanceCycleModel(); maintenanceCycleModel.MaintenanceTypes = new string[9]; maintenanceCycleModel.MaintenanceCycleId = cycle.MaintenanceCycleId; maintenanceCycleModel.Name = cycle.Name; maintenanceCycleModel.ShowName = cycle.ShowName; MaintenanceYear maintenanceYear = new MaintenanceYear(); for (int i = 0; i <= 8; i++) { maintenanceYear = cycle.MaintenanceYears.FirstOrDefault(x => x.Year == i); if (maintenanceYear != null) { maintenanceCycleModel.MaintenanceTypes[i] = maintenanceYear.MaintenanceType.Name; } } return(maintenanceCycleModel); }
public void Create(MaintenanceCycleModel maintenanceCycleModel) { MaintenanceCycle maintenanceCycle = new MaintenanceCycle(); MaintenanceYear maintenanceYear; List <MaintenanceType> maintenanceTypes = new List <MaintenanceType>(dataBase.MaintenanceTypes.GetAll()); maintenanceCycle.Name = maintenanceCycleModel.Name; maintenanceCycle.ShowName = maintenanceCycleModel.ShowName; maintenanceCycle.MaintenanceYears = new List <MaintenanceYear>(); dataBase.MaintenanceCycles.Create(maintenanceCycle); for (int i = 0; i < maintenanceCycleModel.MaintenanceTypes.Length; i++) { if (maintenanceCycleModel.MaintenanceTypes[i] != null) { maintenanceYear = new MaintenanceYear(); maintenanceYear.Year = i; maintenanceYear.MaintenanceType = maintenanceTypes.First(x => x.Name == maintenanceCycleModel.MaintenanceTypes[i]); maintenanceYear.MaintenanceCycle = maintenanceCycle; dataBase.MaintenanceYears.Create(maintenanceYear); } } dataBase.MaintenanceCycles.Create(maintenanceCycle); dataBase.Save(); }