Exemple #1
0
        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 void Delete(MaintenanceCycle deletedMaintenanceCycle, MaintenanceCycle newMaintenanceCycle)
        {
            List <MaintainedEquipmentByCycle> equipments = GetAllMaintainedEquipments(deletedMaintenanceCycle.MaintenanceCycleId);

            if (equipments.Count != 0)
            {
                foreach (MaintainedEquipmentByCycle equipment in equipments)
                {
                    if (equipment is Device)
                    {
                        BaseDeviceService deviceService = new BaseDeviceService(dataBase);
                        deviceService.UpdateRecords(deletedMaintenanceCycle, newMaintenanceCycle, (Device)equipment);
                    }
                    else if (equipment is AdditionalWork)
                    {
                        AdditionalWorkService combineDeviceService = new AdditionalWorkService(dataBase);
                        combineDeviceService.UpdateRecords(deletedMaintenanceCycle, newMaintenanceCycle, (AdditionalWork)equipment);
                    }
                }
                dataBase.Save();
            }
        }