public int GetSectorId(string sectorName) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObj = db.Sectors.Where(s => s.Name.ToLower().Trim().Replace(" ", string.Empty) == sectorName.ToLower().Trim().Replace(" ", string.Empty)).ToList(); if (!myObj.Any()) { var sct = new Sector { Name = sectorName.Trim() }; var processedItem = db.Sectors.Add(sct); db.SaveChanges(); return(processedItem.SectorId); } return(myObj[0].SectorId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(1); } }
public int AddWellWorkoverCheckDuplicates(WellWorkover wellWorkover, int wellId, int wellWorkOverReasonId, int month, long year) { try { if (wellWorkover == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.WellWorkovers.Count(m => m.WellId == wellId && m.WellWorkOverReasonId == wellWorkOverReasonId && m.EquipmentId == wellWorkover.EquipmentId && m.Month == month && m.Year == year) > 0) { return(-3); } var processedItem = db.WellWorkovers.Add(wellWorkover); db.SaveChanges(); return(processedItem.WellWorkOverId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public List <long> GetWellWorkoverYears() { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = (from x in db.WellWorkovers where x.Year > 0 select x.Year).ToList(); if (!myObjList.Any()) { return(new List <long>()); } var newList = new List <long>(); myObjList.ForEach(m => { if (!newList.Exists(x => x == m)) { newList.Add(m); } }); return(newList); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <long>()); } }
public int UpdateLeaseTypeCheckDuplicate(LeaseType leaseType) { try { if (leaseType == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.LeaseTypes.Any()) { if (db.LeaseTypes.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == leaseType.Name.ToLower().Replace(" ", string.Empty) && m.LeaseTypeId != leaseType.LeaseTypeId) > 0) { return(-3); } } db.LeaseTypes.Attach(leaseType); db.Entry(leaseType).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public List <ProjectMilestoneObject> GetProjectMileStones() { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = db.ProjectMileStones.ToList(); if (!myObjList.Any()) { return(new List <ProjectMilestoneObject>()); } var newList = new List <ProjectMilestoneObject>(); myObjList.ForEach(m => newList.Add(new ProjectMilestoneObject { ProjectMileStoneId = m.ProjectMileStoneId, Title = m.Title })); return(newList.OrderBy(m => m.Title).ToList()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <ProjectMilestoneObject>()); } }
public List <IncidentHistory> GetAllOrderedIncidentHistories() { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = db.IncidentHistories.Include("Company").Include("IncidentType").ToList(); if (!myObjList.Any()) { return(new List <IncidentHistory>()); } myObjList.ForEach(m => { m.IncidentTypeName = m.IncidentType.Name; m.CompanyName = m.Company.Name; m.Date = m.IncidentDate.ToString("dd/MM/yyyy"); }); return(myObjList.OrderBy(m => m.IncidentHistoryId).ToList()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <IncidentHistory>()); } }
public bool DeleteLeaseTypeCheckReferences(int leaseTypeId) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Blocks.Count(m => m.LeaseTypeId == leaseTypeId) > 0) { return(false); } var myObj = db.LeaseTypes.Where(s => s.LeaseTypeId == leaseTypeId).ToList(); if (!myObj.Any()) { return(false); } db.LeaseTypes.Remove(myObj[0]); var txx = db.SaveChanges(); return(txx > 0); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(false); } }
public int UpdateBlockCheckDuplicate(Block block) { try { if (block == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Blocks.Any()) { if (db.Blocks.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == block.Name.ToLower().Replace(" ", string.Empty) && m.BlockId != block.BlockId) > 0) { return(-3); } } db.Blocks.Attach(block); db.Entry(block).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int GetBlockId(string blockName) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObj = db.Blocks.Where(s => s.Name.ToLower().Replace(" ", string.Empty).Trim() == blockName.ToLower().Replace(" ", string.Empty).Trim()).ToList(); //if (!myObj.Any()) //{ // var block = new Block { Name = blockName, BlockTypeId = blockId, TerrainId = 1}; // var processedBlocks = db.Blocks.Add(block); // db.SaveChanges(); // return processedBlocks.BlockId; //} if (!myObj.Any()) { return(0); } return(myObj[0].BlockId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(1); } }
public int AddWellClassificationCheckDuplicate(WellClassification wellClassification) { try { if (wellClassification == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.WellClassifications.Any()) { if (db.WellClassifications.Count(m => m.WellClassId == wellClassification.WellClassId && m.WellId == wellClassification.WellId) > 0) { return(-3); } } var txx = db.WellClassifications.Add(wellClassification); db.SaveChanges(); return(txx.WellClassificationId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateWellClassification2(WellClassification wellClassification) { try { if (wellClassification == null || wellClassification.WellClassificationId < 1) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { var entityToUpdate = db.WellClassifications.ToList().Find(m => m.WellClassificationId == wellClassification.WellClassificationId); if (entityToUpdate == null || entityToUpdate.WellClassificationId < 1) { return(-2); } entityToUpdate.WellClassId = wellClassification.WellClassId; entityToUpdate.WellId = wellClassification.WellId; db.Entry(entityToUpdate).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateMilestoneStatusCheckDuplicate(MilestoneStatu milestoneStatus) { try { if (milestoneStatus == null) { return -2; } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.MilestoneStatus.Any()) { if (db.MilestoneStatus.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == milestoneStatus.Name.ToLower().Replace(" ", string.Empty) && m.MilestoneStatusId != milestoneStatus.MilestoneStatusId) > 0) { return -3; } } db.MilestoneStatus.Attach(milestoneStatus); db.Entry(milestoneStatus).State = EntityState.Modified; return db.SaveChanges(); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return 0; } }
public int AddMilestoneStatusCheckDuplicate(MilestoneStatu milestoneStatus) { try { if (milestoneStatus == null) { return -2; } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.MilestoneStatus.Any()) { if (db.MilestoneStatus.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == milestoneStatus.Name.ToLower().Replace(" ", string.Empty)) > 0) { return -3; } } var processedItem = db.MilestoneStatus.Add(milestoneStatus); db.SaveChanges(); return processedItem.MilestoneStatusId; } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return 0; } }
public bool DeleteMilestoneStatuCheckReferences(int milestoneStatusId) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.ProjectMileStones.Count(m => m.MileStoneStatusId == milestoneStatusId) > 0) { return false; } var myObj = db.MilestoneStatus.Where(s => s.MilestoneStatusId == milestoneStatusId).ToList(); if (!myObj.Any()) { return false; } db.MilestoneStatus.Remove(myObj[0]); var txx = db.SaveChanges(); return txx > 0; } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return false; } }
public List <IncidentHistory> GetAllOrderedIncidentHistories(int itemsPerPage, int pageNumber, out int dataCount) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.IncidentHistories.Any()) { dataCount = db.IncidentHistories.Count(); var myObjList = db.IncidentHistories.OrderBy(m => m.IncidentHistoryId).Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).Include("Company").Include("IncidentType").ToList(); if (!myObjList.Any()) { return(new List <IncidentHistory>()); } myObjList.ForEach(m => { m.IncidentTypeName = m.IncidentType.Name; m.CompanyName = m.Company.Name; m.Date = m.IncidentDate.ToString("dd/MM/yyyy"); }); return(myObjList.OrderBy(m => m.IncidentHistoryId).ToList()); } dataCount = 0; return(new List <IncidentHistory>()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); dataCount = 0; return(new List <IncidentHistory>()); } }
public List <BlockObject> GetCompanyBlocksWithFields(long companyId) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = (from b in db.Blocks.Where(m => m.CompanyId == companyId && m.Fields.Any()) select new BlockObject { BlockId = b.BlockId, Name = b.Name }).ToList(); if (!myObjList.Any()) { return(new List <BlockObject>()); } return(myObjList.OrderBy(m => m.Name).ToList()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <BlockObject>()); } }
public List <string> GetIncidentYears() { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = (from x in db.IncidentHistories select x.IncidentDate).ToList(); if (!myObjList.Any()) { return(new List <string>()); } var newList = new List <string>(); myObjList.ForEach(m => { var tty = m.Year.ToString(CultureInfo.InvariantCulture); if (!string.IsNullOrEmpty(tty)) { if (!newList.Exists(x => x == tty)) { newList.Add(tty); } } }); return(newList); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <string>()); } }
public int AddBlockCheckDuplicate(Block block) { try { if (block == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Blocks.Any()) { if (db.Blocks.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == block.Name.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } } var processedBlock = db.Blocks.Add(block); db.SaveChanges(); return(processedBlock.BlockId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int GetLeaseTypeIdByName(string leaseTypeName) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObj = db.LeaseTypes.Where(s => s.Name.Trim().ToLower().Replace(" ", "") == leaseTypeName.Trim().ToLower().Replace(" ", "")).ToList(); if (!myObj.Any()) { var newLeaseType = new LeaseType { Name = leaseTypeName }; var processedLeaseType = db.LeaseTypes.Add(newLeaseType); db.SaveChanges(); return(processedLeaseType.LeaseTypeId); } return(myObj[0].LeaseTypeId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateWellClassCheckDuplicate(WellClass wellClass) { try { if (wellClass == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.WellClasses.Any()) { if (db.WellClasses.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == wellClass.Name.ToLower().Replace(" ", string.Empty) && m.WellClassId != wellClass.WellClassId) > 0) { return(-3); } } db.WellClasses.Attach(wellClass); db.Entry(wellClass).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddLeaseTypeCheckDuplicate(LeaseType leaseType) { try { if (leaseType == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.LeaseTypes.Any()) { if (db.LeaseTypes.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == leaseType.Name.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } } var processedItem = db.LeaseTypes.Add(leaseType); db.SaveChanges(); return(processedItem.LeaseTypeId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public List <FieldReportObject> GetFieldsByBlockId(int blockId) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = db.Fields.Where(m => m.BlockId == blockId).ToList(); if (!myObjList.Any()) { return(new List <FieldReportObject>()); } var newList = new List <FieldReportObject>(); myObjList.ForEach(m => newList.Add(new FieldReportObject { Name = m.Name, FieldId = m.FieldId })); return(newList.OrderBy(m => m.Name).ToList()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <FieldReportObject>()); } }
public List <ProjectMileStone> GetAllOrderedProjectMileStones(int itemsPerPage, int pageNumber, out int dataCount) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.ProjectMileStones.Any()) { dataCount = db.ProjectMileStones.Count(); var myObjList = db.ProjectMileStones.OrderBy(m => m.Title).Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).Include("Project").Include("MilestoneStatu").ToList(); if (!myObjList.Any()) { return(new List <ProjectMileStone>()); } return(myObjList); } dataCount = 0; return(new List <ProjectMileStone>()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); dataCount = 0; return(new List <ProjectMileStone>()); } }
public int AddFieldCheckDuplicate(Field field) { try { if (field == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Fields.Any()) { if (db.Fields.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == field.Name.ToLower().Replace(" ", string.Empty) && m.CompanyId == field.CompanyId) > 0) { return(-3); } } var processedItem = db.Fields.Add(field); db.SaveChanges(); return(processedItem.FieldId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public List <WellWorkover> GetAllOrderedWellWorkovers(int itemsPerPage, int pageNumber, out int dataCount) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.WellWorkovers.Any()) { dataCount = db.WellWorkovers.Count(); var myObjList = db.WellWorkovers.OrderBy(m => m.WellWorkOverId).Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).Include("Equipment").Include("Well").Include("WellWorkOverReason").ToList(); if (!myObjList.Any()) { return(new List <WellWorkover>()); } return(myObjList); } dataCount = 0; return(new List <WellWorkover>()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); dataCount = 0; return(new List <WellWorkover>()); } }
public Field GetFielAndCompanyIds(string fieldName) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObj = db.Fields.Where(s => s.Name.ToLower().Trim().Replace(" ", string.Empty) == fieldName.ToLower().Trim().Replace(" ", string.Empty)).ToList(); if (!myObj.Any()) { var field = new Field { Name = fieldName, ZoneId = 1, TerrainId = 1, CompanyId = 1 }; var processedField = db.Fields.Add(field); db.SaveChanges(); return(processedField); } var ttd = myObj[0]; return(ttd); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new Field { Name = fieldName, ZoneId = 1, TerrainId = 1, CompanyId = 1 }); } }
public List <WellWorkover> GetAllOrderedWellWorkoversByMonth(int searchMonth, int searchYear) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { if (searchYear < 1) { return(new List <WellWorkover>()); } var myObjList = db.WellWorkovers.Where(m => m.Year.Equals(searchYear) && m.Month.Equals(searchMonth)).Include("Equipment").Include("Well").Include("WellWorkOverReason").ToList(); if (!myObjList.Any()) { return(new List <WellWorkover>()); } return(myObjList.OrderBy(m => m.WellWorkOverId).ToList()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <WellWorkover>()); } }
public List <FieldReportObject> GetFieldsByTerrain(int blockId) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = db.Fields.Where(m => m.TerrainId == blockId).Include("Block").Include("Terrain").Include("Company").Include("Zone").ToList(); if (!myObjList.Any()) { return(new List <FieldReportObject>()); } var newList = new List <FieldReportObject>(); myObjList.ForEach(m => newList.Add(new FieldReportObject { Name = m.Name, BlockName = m.Block.Name, TerrainName = m.Terrain.Name, CompanyName = m.Company.Name, TechnicalAllowable = (float?)m.TechnicalAllowable, ZoneName = m.Zone.Name })); return(newList.OrderBy(m => m.Name).ToList()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <FieldReportObject>()); } }
public List <WellWorkoverReportObject> GetMoreWellWorkovers(int itemsPerPage, int pageNumber) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObjList = db.WellWorkovers.OrderBy(m => m.WellWorkOverId).Skip((pageNumber - 1) * itemsPerPage).Take(itemsPerPage).Include("Equipment").Include("Well").Include("WellWorkOverReason").ToList(); if (!myObjList.Any()) { return(new List <WellWorkoverReportObject>()); } var tsdfg = new List <WellWorkoverReportObject>(); myObjList.ForEach(m => tsdfg.Add(new WellWorkoverReportObject { WellWorkOverId = m.WellWorkOverId, WellName = m.Well.Name, EquipmentName = m.Equipment.Name, Reason = m.WellWorkOverReason.Title, Year = m.Year, MonthStr = Enum.GetName(typeof(Months), m.Month) })); return(tsdfg); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(new List <WellWorkoverReportObject>()); } }
public int AddWellTypeCheckDuplicate(WellType wellType) { try { if (wellType == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.WellTypes.Any()) { if (db.WellTypes.Count(m => m.Title.ToLower().Replace(" ", string.Empty) == wellType.Title.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } } db.WellTypes.Add(wellType); return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }