public int AddWellCheckDuplicate(Well well) { try { if (well == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Wells.Any()) { if (db.Wells.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == well.Name.ToLower().Replace(" ", string.Empty)) > 0) { return(-3); } } var processedItem = db.Wells.Add(well); db.SaveChanges(); if (db.WellClassifications.Any()) { if (db.WellClassifications.Count(m => m.WellId == processedItem.WellId) > 0) { return(-4); } } var newWellClassification = new WellClassification { WellClassId = well.WellClassId, WellId = processedItem.WellId }; var classidication = new WellClassificationServices().AddWellClassificationCheckDuplicate(newWellClassification); if (classidication < 1) { return(-2); } return(processedItem.WellId); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int CreateWellClassAddClassification(string wellClassName, int wellId) { try { using (var db = new DPRDataMigrationEngineDBEntities()) { var myObj = db.WellClasses.Where(s => s.Name.ToLower().Replace(" ", string.Empty).Trim() == wellClassName.ToLower().Replace(" ", string.Empty).Trim()).ToList(); if (!myObj.Any()) { var wellClass = new WellClass { Name = wellClassName.Trim() }; var processedWellClass = db.WellClasses.Add(wellClass); db.SaveChanges(); if (processedWellClass.WellClassId > 0) { var newWellClassification = new WellClassification { WellClassId = processedWellClass.WellClassId, WellId = wellId }; var processedWellClassification = new WellClassificationServices().AddWellClassificationCheckDuplicate(newWellClassification); return(processedWellClassification); } } var edt = new WellClassification { WellClassId = myObj[0].WellClassId, WellId = wellId }; var dsx = new WellClassificationServices().AddWellClassificationCheckDuplicate(edt); return(dsx); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateWellCheckDuplicate(Well well) { try { if (well == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { if (db.Wells.Any()) { if (db.Wells.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == well.Name.ToLower().Replace(" ", string.Empty) && m.WellId != well.WellId && m.FieldId == well.FieldId) > 0) { return(-3); } } var newWellClassification = new WellClassification { WellClassId = well.WellClassId, WellId = well.WellId, WellClassificationId = well.WellClassificationId }; var classidicationUpdate = new WellClassificationServices().UpdateWellClassification2(newWellClassification); if (classidicationUpdate < 1) { return(-2); } db.Wells.Attach(well); db.Entry(well).State = EntityState.Modified; return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }