public DatasetSchedulingDetails GetDatasetSchedulingDetails(int datasetId, string loadType) { try { using (_dbContext = string.IsNullOrEmpty(_connectionString) ? _dbContext : new ZionContext(_connectionString)) { DatasetSchedulingDetails schedulingDetails = (from scheduler in _dbContext.DatasetSchedulingDetails where scheduler.DatasetId == datasetId && scheduler.LoadType == loadType select scheduler).FirstOrDefault(); return(schedulingDetails); } } catch { throw; } }
public void UpdateDatasetSchedulingDetails(List <DatasetSchedulingDetails> schedulingDetails) { using (_dbContext = new ZionContext(_connectionString)) { int counter = 0; foreach (DatasetSchedulingDetails s in schedulingDetails) { counter++; int datasetId = schedulingDetails.Where(x => x != null).Select(d => d.DatasetId).FirstOrDefault(); if (s != null && s.DatasetDetailsId != 0) { _dbContext.Entry(s).State = EntityState.Modified; } else if (s != null && s.DatasetDetailsId == 0) { _dbContext.DatasetSchedulingDetails.Add(s); } else if (s == null && counter == 1) { DatasetSchedulingDetails sDetails = _dbContext.DatasetSchedulingDetails.Where(d => d.DatasetId == datasetId && d.LoadType.ToLower() == "full").FirstOrDefault(); if (sDetails != null) { _dbContext.DatasetSchedulingDetails.Remove(sDetails); } } else if (s == null && counter == 2) { DatasetSchedulingDetails sDetails = _dbContext.DatasetSchedulingDetails.Where(d => d.DatasetId == datasetId && d.LoadType.ToLower() == "delta").FirstOrDefault(); if (sDetails != null) { _dbContext.DatasetSchedulingDetails.Remove(sDetails); } } } _dbContext.SaveChanges(); } }