public JobExtension DeleteJobExtension(int jobExtensionID)
        {
            JobExtension dbEntry = context.JobsExtensions
                                   .FirstOrDefault(p => p.JobExtensionID == jobExtensionID);

            if (dbEntry != null)
            {
                context.JobsExtensions.Remove(dbEntry);
                context.SaveChanges();
            }
            return(dbEntry);
        }
        public Job DeleteEngJob(int JobID)
        {
            Job dbEntry = context.Jobs
                          .FirstOrDefault(p => p.JobID == JobID);
            JobExtension jobExtension = context.JobsExtensions
                                        .FirstOrDefault(p => p.JobID == JobID);
            HydroSpecific hydroSpecific = context.HydroSpecifics
                                          .FirstOrDefault(p => p.JobID == JobID);
            GenericFeatures genericFeatures = context.GenericFeaturesList
                                              .FirstOrDefault(p => p.JobID == JobID);
            Indicator indicator = context.Indicators
                                  .FirstOrDefault(p => p.JobID == JobID);
            HoistWayData hoistWayData = context.HoistWayDatas
                                        .FirstOrDefault(p => p.JobID == JobID);

            if (dbEntry != null)
            {
                context.Jobs.Remove(dbEntry);
                context.SaveChanges();
            }
            if (jobExtension != null)
            {
                context.JobsExtensions.Remove(jobExtension);
                context.SaveChanges();
            }
            if (hydroSpecific != null)
            {
                context.HydroSpecifics.Remove(hydroSpecific);
                context.SaveChanges();
            }
            if (genericFeatures != null)
            {
                context.GenericFeaturesList.Remove(genericFeatures);
                context.SaveChanges();
            }
            if (indicator != null)
            {
                context.Indicators.Remove(indicator);
                context.SaveChanges();
            }
            if (hoistWayData != null)
            {
                context.HoistWayDatas.Remove(hoistWayData);
                context.SaveChanges();
            }
            return(dbEntry);
        }
 public void SaveJobExtension(JobExtension jobExtension)
 {
     if (jobExtension.JobExtensionID == 0)
     {
         context.JobsExtensions.Add(jobExtension);
     }
     else
     {
         JobExtension dbEntry = context.JobsExtensions
                                .FirstOrDefault(p => p.JobExtensionID == jobExtension.JobExtensionID);
         if (dbEntry != null)
         {
             dbEntry.JobID             = jobExtension.JobID;
             dbEntry.NumOfStops        = jobExtension.NumOfStops;
             dbEntry.JobTypeMain       = jobExtension.JobTypeMain;
             dbEntry.JobTypeAdd        = jobExtension.JobTypeAdd;
             dbEntry.InputVoltage      = jobExtension.InputVoltage;
             dbEntry.InputPhase        = jobExtension.InputPhase;
             dbEntry.InputFrecuency    = jobExtension.InputFrecuency;
             dbEntry.DoorGate          = jobExtension.DoorGate;
             dbEntry.DoorHoist         = jobExtension.DoorHoist;
             dbEntry.InfDetector       = jobExtension.InfDetector;
             dbEntry.MechSafEdge       = jobExtension.MechSafEdge;
             dbEntry.HeavyDoors        = jobExtension.HeavyDoors;
             dbEntry.CartopDoorButtons = jobExtension.CartopDoorButtons;
             dbEntry.DoorHold          = jobExtension.DoorHold;
             dbEntry.Nudging           = jobExtension.Nudging;
             dbEntry.DoorBrand         = jobExtension.DoorBrand;
             dbEntry.DoorModel         = jobExtension.DoorModel;
             dbEntry.SCOP      = jobExtension.SCOP;
             dbEntry.SHC       = jobExtension.SHC;
             dbEntry.SHCRisers = jobExtension.SHCRisers;
             dbEntry.AUXCOP    = jobExtension.AUXCOP;
         }
     }
     context.SaveChanges();
 }
 public void SaveEngJobView(JobViewModel viewModelToSave)
 {
     SaveJob(viewModelToSave.CurrentJob);
     if (viewModelToSave.CurrentJobExtension != null)
     {
         if (viewModelToSave.CurrentJobExtension.JobID != 0)
         {
             JobExtension jobExtension = JobsExtensions.FirstOrDefault(j => j.JobID == viewModelToSave.CurrentJobExtension.JobID);
             if (jobExtension == null)
             {
                 SaveJobExtension(viewModelToSave.CurrentJobExtension);
             }
             else
             {
                 viewModelToSave.CurrentJobExtension.JobExtensionID = jobExtension.JobExtensionID;
                 SaveJobExtension(viewModelToSave.CurrentJobExtension);
             }
         }
     }
     if (viewModelToSave.CurrentHydroSpecific != null)
     {
         if (viewModelToSave.CurrentHydroSpecific.JobID != 0)
         {
             HydroSpecific hydroSpecific = HydroSpecifics.FirstOrDefault(j => j.JobID == viewModelToSave.CurrentHydroSpecific.JobID);
             if (hydroSpecific == null)
             {
                 SaveHydroSpecific(viewModelToSave.CurrentHydroSpecific);
             }
             else
             {
                 viewModelToSave.CurrentHydroSpecific.HydroSpecificID = hydroSpecific.HydroSpecificID;
                 SaveHydroSpecific(viewModelToSave.CurrentHydroSpecific);
             }
         }
     }
     if (viewModelToSave.CurrentGenericFeatures != null)
     {
         if (viewModelToSave.CurrentGenericFeatures.JobID != 0)
         {
             GenericFeatures genericFeatures = GenericFeaturesList.FirstOrDefault(j => j.JobID == viewModelToSave.CurrentGenericFeatures.JobID);
             if (genericFeatures == null)
             {
                 SaveGenericFeatures(viewModelToSave.CurrentGenericFeatures);
             }
             else
             {
                 viewModelToSave.CurrentGenericFeatures.GenericFeaturesID = genericFeatures.GenericFeaturesID;
                 SaveGenericFeatures(viewModelToSave.CurrentGenericFeatures);
             }
         }
     }
     if (viewModelToSave.CurrentIndicator != null)
     {
         if (viewModelToSave.CurrentIndicator.JobID != 0)
         {
             Indicator indicator = Indicators.FirstOrDefault(j => j.JobID == viewModelToSave.CurrentIndicator.JobID);
             if (indicator == null)
             {
                 SaveIndicator(viewModelToSave.CurrentIndicator);
             }
             else
             {
                 viewModelToSave.CurrentIndicator.IndicatorID = indicator.IndicatorID;
                 SaveIndicator(viewModelToSave.CurrentIndicator);
             }
         }
     }
     if (viewModelToSave.CurrentHoistWayData != null)
     {
         if (viewModelToSave.CurrentHoistWayData.JobID != 0)
         {
             HoistWayData hoistway = HoistWayDatas.FirstOrDefault(j => j.JobID == viewModelToSave.CurrentHoistWayData.JobID);
             if (hoistway == null)
             {
                 SaveHoistWayData(viewModelToSave.CurrentHoistWayData);
             }
             else
             {
                 viewModelToSave.CurrentHoistWayData.HoistWayDataID = hoistway.HoistWayDataID;
                 SaveHoistWayData(viewModelToSave.CurrentHoistWayData);
             }
         }
     }
 }