Exemple #1
0
        public void DeleteTrailer(string id)
        {
            var trailerToRemove = _trailerRepository.Get(c => c.TrailerC == id);

            if (trailerToRemove != null)
            {
                _trailerRepository.Delete(trailerToRemove);

                // delete in MaintenancePlan_D
                var maintenanceItemsPlan = _maintenancePlanDetailRepository.Query(x => x.ObjectI == "1" && x.Code == id);
                if (maintenanceItemsPlan != null)
                {
                    foreach (var deleteItem in maintenanceItemsPlan)
                    {
                        _maintenancePlanDetailRepository.Delete((deleteItem));
                    }
                }
                // delete Maintenance_D
                //var maintenanceItems = _maintenanceDetailRepository.Query(x => x.ObjectI == "1" && x.Code == id);
                //if (maintenanceItems != null)
                //{
                //	foreach (var deleteItem in maintenanceItems)
                //	{
                //		_maintenanceDetailRepository.Delete(deleteItem);
                //	}
                //}

                // delete in inspectionPlan_D
                _inspectionPlanDetailService.Delete("1", id);



                SaveTrailer();
            }
        }
Exemple #2
0
        public void UpdatePlan(List <MaintenanceDetailViewModel> data, string objectI, string code)
        {
            if (data.Any() == false)
            {
                var deleteItems = _maintenancePlanDetailRepository.Query(x => x.ObjectI == objectI &&
                                                                         x.Code == code);
                foreach (var item in deleteItems)
                {
                    _maintenancePlanDetailRepository.Delete(item);
                }
            }
            else
            {
                foreach (var item in data)
                {
                    var dataItem = _maintenancePlanDetailRepository.Query(
                        x => x.ObjectI == objectI &&
                        x.Code == code &&
                        x.MaintenanceItemC == item.MaintenanceItemC).FirstOrDefault();

                    if (dataItem != null)
                    {
                        dataItem.PlanMaintenanceD  = item.NextMaintenanceD;
                        dataItem.PlanMaintenanceKm = item.NextMaintenanceKm;

                        _maintenancePlanDetailRepository.Update(dataItem);
                    }
                    else
                    {
                        if ((item.NoticeI == "1" && item.NextMaintenanceD != null) || (item.NoticeI == "2" && item.NextMaintenanceKm != null))
                        {
                            MaintenancePlan_D addItem = new MaintenancePlan_D()
                            {
                                ObjectI           = objectI,
                                Code              = code,
                                MaintenanceItemC  = item.MaintenanceItemC,
                                PlanMaintenanceD  = item.NextMaintenanceD,
                                PlanMaintenanceKm = item.NextMaintenanceKm
                            };

                            _maintenancePlanDetailRepository.Add(addItem);
                        }
                    }
                }
            }
            SaveMaintenancePlanDetail();
        }