public void SaveHoistWayData(HoistWayData hoistWayData)
 {
     if (hoistWayData.HoistWayDataID == 0)
     {
         context.HoistWayDatas.Add(hoistWayData);
     }
     else
     {
         HoistWayData dbEntry = context.HoistWayDatas
                                .FirstOrDefault(p => p.HoistWayDataID == hoistWayData.HoistWayDataID);
         if (dbEntry != null)
         {
             dbEntry.JobID                 = hoistWayData.JobID;
             dbEntry.FrontFirstServed      = hoistWayData.FrontFirstServed;
             dbEntry.RearFirstServed       = hoistWayData.RearFirstServed;
             dbEntry.FrontSecondServed     = hoistWayData.FrontSecondServed;
             dbEntry.RearSecondServed      = hoistWayData.RearSecondServed;
             dbEntry.FrontThirdServed      = hoistWayData.FrontThirdServed;
             dbEntry.RearThirdServed       = hoistWayData.RearThirdServed;
             dbEntry.FrontFourthServed     = hoistWayData.FrontFourthServed;
             dbEntry.RearFourthServed      = hoistWayData.RearFourthServed;
             dbEntry.FrontFifthServed      = hoistWayData.FrontFifthServed;
             dbEntry.RearFifthServed       = hoistWayData.RearFifthServed;
             dbEntry.FrontSexthServed      = hoistWayData.FrontSexthServed;
             dbEntry.RearSexthServed       = hoistWayData.RearSexthServed;
             dbEntry.FrontSeventhServed    = hoistWayData.FrontSeventhServed;
             dbEntry.RearSeventhServed     = hoistWayData.RearSeventhServed;
             dbEntry.FrontEightServed      = hoistWayData.FrontEightServed;
             dbEntry.RearEightServed       = hoistWayData.RearEightServed;
             dbEntry.FrontNinthServed      = hoistWayData.FrontNinthServed;
             dbEntry.RearNinthServed       = hoistWayData.RearNinthServed;
             dbEntry.FrontTenthServed      = hoistWayData.FrontTenthServed;
             dbEntry.RearTenthServed       = hoistWayData.RearTenthServed;
             dbEntry.FrontEleventhServed   = hoistWayData.FrontEleventhServed;
             dbEntry.RearEleventhServed    = hoistWayData.RearEleventhServed;
             dbEntry.FrontTwelvethServed   = hoistWayData.FrontTwelvethServed;
             dbEntry.RearTwelvethServed    = hoistWayData.RearTwelvethServed;
             dbEntry.FrontThirteenthServed = hoistWayData.FrontThirteenthServed;
             dbEntry.RearThirteenthServed  = hoistWayData.RearThirteenthServed;
             dbEntry.FrontFourteenthServed = hoistWayData.FrontFourteenthServed;
             dbEntry.RearFourteenthServed  = hoistWayData.RearFourteenthServed;
             dbEntry.FrontFifteenthServed  = hoistWayData.FrontFifteenthServed;
             dbEntry.RearFifteenthServed   = hoistWayData.RearFifteenthServed;
             dbEntry.FrontSixteenthServed  = hoistWayData.FrontSixteenthServed;
             dbEntry.RearSixteenthServed   = hoistWayData.RearSixteenthServed;
             dbEntry.Capacity              = hoistWayData.Capacity;
             dbEntry.UpSpeed               = hoistWayData.UpSpeed;
             dbEntry.DownSpeed             = hoistWayData.DownSpeed;
             dbEntry.TotalTravel           = hoistWayData.TotalTravel;
             dbEntry.LandingSystem         = hoistWayData.LandingSystem;
         }
     }
     context.SaveChanges();
 }
        public HoistWayData DeleteHoistWayData(int hoistWayDataID)
        {
            HoistWayData dbEntry = context.HoistWayDatas
                                   .FirstOrDefault(p => p.HoistWayDataID == hoistWayDataID);

            if (dbEntry != null)
            {
                context.HoistWayDatas.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 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);
             }
         }
     }
 }