public void TestSetUp() { Logger.Debug($"Executing {TestContext.TestName}"); DevKit = new DevKit200Aspect(TestContext); Well = new Well { Uuid = DevKit.Uid(), Citation = DevKit.Citation("Well"), GeographicLocationWGS84 = DevKit.Location(), SchemaVersion = "2.0", TimeZone = DevKit.TimeZone }; WellCompletion = new WellCompletion { Uuid = DevKit.Uid(), Citation = DevKit.Citation("WellCompletion"), Well = DevKit.DataObjectReference(Well), SchemaVersion = EtpUris.GetUriFamily(typeof(WellCompletion)).Version, }; BeforeEachTest(); OnTestSetUp(); }
public async Task WellCompletion200_PutObject_Can_Add_WellCompletion() { AddParents(); await RequestSessionAndAssert(); var handler = _client.Handler <IStoreCustomer>(); var uri = WellCompletion.GetUri(); var dataObject = CreateDataObject(uri, WellCompletion); // Get Object var args = await GetAndAssert(handler, uri); // Check for message flag indicating No Data Assert.IsNotNull(args?.Header); Assert.AreEqual((int)MessageFlags.NoData, args.Header.MessageFlags); // Put Object await PutAndAssert(handler, dataObject); // Get Object args = await GetAndAssert(handler, uri); // Check Data Object XML Assert.IsNotNull(args?.Message.DataObject); var xml = args.Message.DataObject.GetString(); var result = Parse <WellCompletion>(xml); Assert.IsNotNull(result); }
public ActionResult DeleteWellCompletion(int id) { var wellCompletion = new WellCompletion(); try { if (id < 1) { wellCompletion.Error = "Invalid Selection"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (new WellCompletionServices().DeleteWellCompletionCheckReferences(id)) { wellCompletion.Error = "Well Completion Information was successfully deleted."; wellCompletion.ErrorCode = 1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } wellCompletion.Error = "Process Failed! Please try again later"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletion.Error = "An unknown error was encountered. Please contact the Administrator or try again later."; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } }
public async Task WellCompletion200_PutObject_Can_Add_WellCompletion() { AddParents(); await RequestSessionAndAssert(); var handler = _client.Handler <IStoreCustomer>(); var uri = WellCompletion.GetUri(); var dataObject = CreateDataObject(uri, WellCompletion); // Get Object Expecting it Not to Exist await GetAndAssert(handler, uri, Energistics.Etp.EtpErrorCodes.NotFound); // Put Object await PutAndAssert(handler, dataObject); // Get Object var args = await GetAndAssert(handler, uri); // Check Data Object XML Assert.IsNotNull(args?.Message.DataObject); var xml = args.Message.DataObject.GetString(); var result = Parse <WellCompletion>(xml); Assert.IsNotNull(result); }
public async Task WellCompletion200_PutObject_Can_Update_WellCompletion() { AddParents(); await RequestSessionAndAssert(); var handler = _client.Handler <IStoreCustomer>(); var uri = WellCompletion.GetUri(); // Add a ExtensionNameValue to Data Object var envName = "TestPutObject"; var env = DevKit.ExtensionNameValue(envName, envName); WellCompletion.ExtensionNameValue = new List <ExtensionNameValue>() { env }; var dataObject = CreateDataObject(uri, WellCompletion); // Get Object Expecting it Not to Exist await GetAndAssert(handler, uri, Energistics.Etp.EtpErrorCodes.NotFound); // Put Object for Add await PutAndAssert(handler, dataObject); // Get Added Object var args = await GetAndAssert(handler, uri); // Check Added Data Object XML Assert.IsNotNull(args?.Message.DataObject); var xml = args.Message.DataObject.GetString(); var result = Parse <WellCompletion>(xml); Assert.IsNotNull(result); Assert.IsNotNull(result.ExtensionNameValue.FirstOrDefault(e => e.Name.Equals(envName))); // Remove Comment from Data Object result.ExtensionNameValue.Clear(); var updateDataObject = CreateDataObject(uri, result); // Put Object for Update await PutAndAssert(handler, updateDataObject); // Get Updated Object args = await GetAndAssert(handler, uri); // Check Added Data Object XML Assert.IsNotNull(args?.Message.DataObject); var updateXml = args.Message.DataObject.GetString(); result = Parse <WellCompletion>(updateXml); Assert.IsNotNull(result); // Test Data Object overwrite Assert.IsNull(result.ExtensionNameValue.FirstOrDefault(e => e.Name.Equals(envName))); }
public async Task WellCompletion141_PutObject_Can_Update_WellCompletion() { AddParents(); await RequestSessionAndAssert(); var handler = _client.Handler <IStoreCustomer>(); var uri = WellCompletion.GetUri(); // Add a Comment to Data Object WellCompletion.CommonData = new CommonData() { Comments = "Test PutObject" }; var dataObject = CreateDataObject <WellCompletionList, WellCompletion>(uri, WellCompletion); // Get Object Expecting it Not to Exist await GetAndAssert(handler, uri, Energistics.Etp.EtpErrorCodes.NotFound); // Put Object for Add await PutAndAssert(handler, dataObject); // Get Added Object var args = await GetAndAssert(handler, uri); // Check Added Data Object XML Assert.IsNotNull(args?.Message.DataObject); var xml = args.Message.DataObject.GetString(); var result = Parse <WellCompletionList, WellCompletion>(xml); Assert.IsNotNull(result); Assert.IsNotNull(result.CommonData.Comments); // Remove Comment from Data Object result.CommonData.Comments = null; var updateDataObject = CreateDataObject <WellCompletionList, WellCompletion>(uri, result); // Put Object for Update await PutAndAssert(handler, updateDataObject); // Get Updated Object args = await GetAndAssert(handler, uri); // Check Added Data Object XML Assert.IsNotNull(args?.Message.DataObject); var updateXml = args.Message.DataObject.GetString(); result = Parse <WellCompletionList, WellCompletion>(updateXml); Assert.IsNotNull(result); // Test Data Object overwrite Assert.IsNull(result.CommonData.Comments); }
public async Task WellCompletion200_GetResources_Can_Get_All_WellCompletion_Resources() { AddParents(); DevKit.AddAndAssert(WellCompletion); await RequestSessionAndAssert(); var uri = WellCompletion.GetUri(); var parentUri = uri.Parent; await GetResourcesAndAssert(WellCompletion.Well.GetUri()); var folderUri = parentUri.Append(uri.ObjectType); await GetResourcesAndAssert(folderUri); }
protected override void OnTestSetUp() { base.OnTestSetUp(); WellCompletion = new WellCompletion { Uid = DevKit.Uid(), Name = DevKit.Name("WellCompletion"), UidWell = Well.Uid, NameWell = Well.Name, }; WellboreCompletion.NameWellCompletion = WellCompletion.Name; WellboreCompletion.UidWellCompletion = WellCompletion.Uid; }
protected override void PrepareData() { Well = new Well { Uuid = DevKit.Uid(), Citation = DevKit.Citation("Well"), GeographicLocationWGS84 = DevKit.Location(), SchemaVersion = "2.0", TimeZone = DevKit.TimeZone }; WellCompletion = new WellCompletion { Uuid = DevKit.Uid(), Citation = DevKit.Citation("WellCompletion"), Well = DevKit.DataObjectReference(Well), SchemaVersion = EtpUris.GetUriFamily(typeof(WellCompletion)).Version, }; }
protected override void PrepareData() { DevKit.Store.CapServerProviders = DevKit.Store.CapServerProviders .Where(x => x.DataSchemaVersion == OptionsIn.DataVersion.Version141.Value) .ToArray(); Well = new Well { Uid = DevKit.Uid(), Name = DevKit.Name("Well"), TimeZone = DevKit.TimeZone }; WellCompletion = new WellCompletion { Uid = DevKit.Uid(), Name = DevKit.Name("WellCompletion"), UidWell = Well.Uid, NameWell = Well.Name, }; QueryEmptyList = DevKit.List(new WellCompletion()); }
private static GenericValidator ValidateControl(WellCompletion model) { var gVal = new GenericValidator(); try { if (model.WellId < 1) { gVal.Error = "Please select a invalid Well information."; gVal.Code = 0; return(gVal); } if (model.EquipmentId < 1) { gVal.Error = "Please select a valid Equipment"; gVal.Code = 0; return(gVal); } if (model.WellCompletionTypeId < 1) { gVal.Error = "Please select a valid Well Completion Type"; gVal.Code = 0; return(gVal); } gVal.Code = 1; return(gVal); } catch (Exception ex) { gVal.Error = "Process validation failed. Please supply all required entries and try again."; gVal.Code = 0; return(gVal); } }
private WellCompletion ProcessRecord2(DataRowView dv, ref string msg, int completionTypeId) { if (dv == null) { return(null); } try { var wellName = dv.Row["wellname"].ToString().Replace(" ", "").Replace(",", "").Trim(); if (string.IsNullOrEmpty(wellName.Trim())) { return(null); } var mInfo = new WellCompletion { WellName = wellName, }; var ttcg = new WellServices().GetWellIdByName(wellName); if (ttcg < 1) { msg = "Well Information could not be processed"; return(null); } mInfo.WellId = ttcg; var year = dv.Row["datecompleted(yyyy/MM/dd)"].ToString().Trim(); if (string.IsNullOrEmpty(year)) { msg = "Completion Date is empty."; return(null); } else { DateTime outYear; var yrResult = DateTime.TryParse(year, out outYear); if (!yrResult) { msg = "Completion Date is empty."; return(null); } else { mInfo.DateCompleted = outYear; } } var completionStatus = dv.Row["isinitialcompletion(YES/NO)"].ToString().Trim(); if (string.IsNullOrEmpty(completionStatus)) { msg = "Please indicate if Well Completion is Initial or ortherwise."; return(null); } else { if (completionStatus.Trim().ToLower().Replace(" ", "") == "yes") { mInfo.IsInitial = true; } if (completionStatus.Trim().ToLower().Replace(" ", "") == "no") { mInfo.IsInitial = false; } } double l1; double up1; double l2; double up2; var lowerInter1 = dv.Row["lower_interval_1"].ToString().Trim(); if (string.IsNullOrEmpty(lowerInter1)) { msg = "Please provide lower Interval 1."; return(null); } else { double outLint; var dtResult = double.TryParse(lowerInter1, out outLint); if (!dtResult && outLint < 1) { msg = "Please provide a valid lower Interval 1."; return(null); } else { l1 = outLint; } } var upperInter = dv.Row["upper_interval_1"].ToString().Trim(); if (string.IsNullOrEmpty(upperInter)) { msg = "Please provide Upper Interval 1."; return(null); } else { double outUpint; var dtResult = double.TryParse(upperInter, out outUpint); if (!dtResult && outUpint < 1) { msg = "Please provide a valid Upper Interval 1."; return(null); } else { up1 = outUpint; } } var lowerInter2 = dv.Row["lower_interval_2"].ToString().Trim(); if (string.IsNullOrEmpty(lowerInter2)) { msg = "Please provide lower Interval 2."; return(null); } else { double outLint2; var dtResult = double.TryParse(lowerInter2, out outLint2); if (!dtResult && outLint2 < 1) { msg = "Please provide a valid lower Interval 2."; return(null); } else { l2 = outLint2; } } var upperInter2 = dv.Row["upper_interval_2"].ToString().Trim(); if (string.IsNullOrEmpty(upperInter2)) { msg = "Please provide Upper Interval 2."; return(null); } else { double outUpint2; var dtResult = double.TryParse(upperInter2, out outUpint2); if (!dtResult && outUpint2 < 1) { msg = "Please provide a valid Upper Interval 2."; return(null); } else { up2 = outUpint2; } } if (!string.IsNullOrEmpty(dv.Row["equipmentused"].ToString().Trim())) { var dfv = dv.Row["equipmentused"].ToString().Trim(); var equipmentId = new EquipmentServices().GetEquipmentId(dfv); if (equipmentId < 1) { msg = "Equipment Information could not be processed"; return(null); } mInfo.EquipmentId = equipmentId; } else { msg = "Equipment used empty."; return(null); } mInfo.WellCompletionTypeId = completionTypeId; var vvz = new WellCompletionServices().AddWellCompletionCheckDuplicate3(mInfo); if (vvz < 1) { msg = "Well Completion Interval for the same Period, Reason, Completion Type and Equipment already exists for this well."; return(null); } var wellCompInt = new WellCompletionInterval { LowerInterval = l1, WellCompletionId = vvz, UpperInterval = up1, DateCompleted = mInfo.DateCompleted.ToString(), LastUpdatedTime = DateTime.Now.ToString("G") }; var vvzk = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(wellCompInt); if (vvzk < 1) { msg = "Well Completion Information could not be processed."; return(null); } var tdd = new WellCompletionInterval { LowerInterval = l2, WellCompletionId = vvz, UpperInterval = up2, DateCompleted = mInfo.DateCompleted.ToString(), LastUpdatedTime = DateTime.Now.ToString("G") }; var vvzk2 = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(tdd); if (vvzk2 < 1) { new WellCompletionIntervalServices().DeleteWellCompletionIntervalCheckReferences(vvzk); msg = "Well Completion Information could not be processed."; return(null); } return(mInfo); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(null); } }
public bool Import(string filePath, string sheetName, ref List <WellCompletion> mList, ref string msg, int completionTypeId) { if (filePath.Length < 3 || new FileInfo(filePath).Exists == false || (Path.GetExtension(filePath) != ".xls" && Path.GetExtension(filePath) != ".xlsx")) { msg = "Invalid Excel File Format"; return(false); } if (sheetName.Length < 1) { msg = "Invalid Excel Sheet Name"; return(false); } var connectionstring = string.Empty; switch (Path.GetExtension(filePath)) { case ".xls": connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=YES;'"; break; case ".xlsx": connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;ImportMixedTypes=Text'"; break; } if (connectionstring == "") { msg = "Process Error! Please try again later"; return(false); } var selectString = ""; if (completionTypeId == 1) { selectString = @"SELECT [wellname], [equipmentused], [isinitialcompletion(YES/NO)], [lower_interval], [upper_interval], [datecompleted(yyyy/MM/dd)] FROM [" + sheetName + "$]"; } if (completionTypeId == 2) { selectString = @"SELECT [wellname], [equipmentused], [isinitialcompletion(YES/NO)], [lower_interval_1], [upper_interval_1], [lower_interval_2], [upper_interval_2], [datecompleted(yyyy/MM/dd)] FROM [" + sheetName + "$]"; } var myCon = new OleDbConnection(connectionstring); try { if (myCon.State == ConnectionState.Closed) { myCon.Open(); } var cmd = new OleDbCommand(selectString, myCon); var adap = new OleDbDataAdapter(cmd); var ds = new DataSet(); adap.Fill(ds); if (ds.Tables.Count < 1) { msg = "Invalid WellCompletion Template!"; return(false); } var dv = new DataView(ds.Tables[0]); if (dv.Count < 1) { msg = "Invalid WellCompletion Template!"; return(false); } msg = string.Empty; var sb = new StringBuilder(); sb.AppendLine("<table width=\"98%\" cellspacing=\"1px\" border=\"1\" cellpadding=\"2px\">"); sb.AppendLine(string.Format("<tr><th width=\"45%\">WellCompletion Name</th><th width=\"55%\">Error</th></tr>")); var errorExist = false; for (var i = 0; i < dv.Count; i++) { var mymsg = string.Empty; var mInfo = new WellCompletion(); var wellName = dv[i].Row["wellname"].ToString().Trim(); if (completionTypeId == 1) { mInfo = ProcessRecord(dv[i], ref mymsg, completionTypeId); } if (completionTypeId == 2) { mInfo = ProcessRecord2(dv[i], ref mymsg, completionTypeId); } if (mInfo == null) { errorExist = true; sb.AppendLine(mymsg.Length > 0 ? string.Format( "<tr border=\"1\"><td width=\"45%\">{0}</td><td width=\"55%\">{1}</td></tr>", wellName, mymsg) : string.Format( "<tr border=\"1\"><td width=\"45%\">{0}</td><td width=\"55%\">Error</td></tr>", wellName)); continue; } mList.Add(mInfo); } sb.AppendLine("</table>"); if (errorExist) { var sbb = new StringBuilder(); sbb.AppendLine("Following error occurred while loading your data template:"); sbb.AppendLine(sb.ToString()); msg = sbb.ToString(); } myCon.Close(); return(true); } catch (Exception ex) { msg = ex.Message; ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); myCon.Close(); return(false); } }
public ActionResult EditWellCompletion(int id) { var wellCompletion = new WellCompletion(); try { if (id < 1) { wellCompletion.Error = "Invalid Selection!"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } var myViewObj = new WellCompletionServices().GetWellCompletion(id); if (myViewObj == null || myViewObj.WellCompletionId < 1) { wellCompletion.Error = "Well Completion Information could not be retrieved."; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } var welllcompObj = new WellCompletionObject { DatecomPletedString = myViewObj.DatecomPletedString, WellCompletionId = myViewObj.WellCompletionId, WellId = myViewObj.WellId, EquipmentId = myViewObj.EquipmentId, WellCompletionTypeId = myViewObj.WellCompletionTypeId, IsInitial = myViewObj.IsInitial }; if (myViewObj.WellCompletionIntervals.Any()) { var intervals = myViewObj.WellCompletionIntervals.ToList(); if (myViewObj.WellCompletionTypeId > 1) { var upperInt = intervals.Max(m => m.UpperInterval); var lowerInt = intervals.Min(m => m.UpperInterval); if (lowerInt > 0) { var interval1 = intervals.Find(m => m.UpperInterval.Equals(lowerInt)); if (interval1 != null && interval1.WellCompletionIntervalId > 0) { welllcompObj.L1 = interval1.LowerInterval; welllcompObj.U1 = interval1.UpperInterval; welllcompObj.IntervalId1 = interval1.WellCompletionIntervalId; } } if (upperInt > 0) { var interval2 = intervals.Find(m => m.UpperInterval.Equals(upperInt)); if (interval2 != null) { welllcompObj.L2 = interval2.LowerInterval; welllcompObj.U2 = interval2.UpperInterval; welllcompObj.IntervalId2 = interval2.WellCompletionIntervalId; welllcompObj.DateCompleted = DateTime.Parse(interval2.DateCompleted); } } } if (myViewObj.WellCompletionTypeId < 2) { welllcompObj.L1 = intervals[0].LowerInterval; welllcompObj.U1 = intervals[0].UpperInterval; welllcompObj.IntervalId1 = intervals[0].WellCompletionIntervalId; welllcompObj.DateCompleted = DateTime.Parse(intervals[0].DateCompleted); } } Session["_wellCompletion"] = myViewObj; Session["_wellCompObj"] = welllcompObj; welllcompObj.ErrorCode = 5; return(Json(welllcompObj, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletion.Error = "An unknown error was encountered. Well Completion Information could not be retrieved."; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditWellCompletion(WellCompletion wellCompletion) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (Session["_wellCompletion"] == null || Session["_wellCompObj"] == null) { wellCompletion.Error = "Session has expired"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } var oldWellCompletion = Session["_wellCompletion"] as WellCompletion; var oldWellCompObj = Session["_wellCompObj"] as WellCompletionObject; if (oldWellCompletion == null || oldWellCompletion.WellCompletionId < 1 || oldWellCompObj == null || oldWellCompObj.WellCompletionId < 1) { wellCompletion.Error = "Session has expired"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (!ModelState.IsValid) { wellCompletion.Error = "Please supply all required entries and try again"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(wellCompletion); if (wx.Code < 1) { wellCompletion.Error = wx.Error; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } oldWellCompletion.EquipmentId = wellCompletion.EquipmentId; oldWellCompletion.WellId = wellCompletion.WellId; oldWellCompletion.WellCompletionTypeId = wellCompletion.WellCompletionTypeId; wellCompletion.IsInitial = wellCompletion.IsInitial; if (wellCompletion.WellCompletionTypeId > 1) { if (wellCompletion.L2 <= 0) { wellCompletion.Error = "Please provide a valid Lower Intervalv 2"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.U2 <= 0) { wellCompletion.Error = "Please provide a valid Upper Interval 2"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.U2 < wellCompletion.L2 || wellCompletion.U2.Equals(wellCompletion.L2)) { wellCompletion.Error = "Please provide a valid Second Upper Interval 2"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } var newCompletionInterval2 = new WellCompletionInterval { LowerInterval = wellCompletion.L2, UpperInterval = wellCompletion.U2, DateCompleted = wellCompletion.DateCompleted.ToString(), LastUpdatedTime = DateTime.Now.ToString("g"), WellCompletionId = oldWellCompletion.WellCompletionId }; if (oldWellCompObj.IntervalId2 > 0) { newCompletionInterval2.WellCompletionIntervalId = oldWellCompObj.IntervalId2; var r = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(newCompletionInterval2); if (r < 1) { wellCompletion.Error = "Well Completion Interval could not be updated"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } if (oldWellCompObj.IntervalId2 < 1) { var r = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(newCompletionInterval2); if (r < 1) { wellCompletion.Error = "Well Completion Interval could not be updated"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } var newCompletionInterval1 = new WellCompletionInterval { LowerInterval = wellCompletion.L1, UpperInterval = wellCompletion.U1, DateCompleted = wellCompletion.DateCompleted.ToString(), LastUpdatedTime = DateTime.Now.ToString("g"), WellCompletionId = oldWellCompletion.WellCompletionId }; if (oldWellCompObj.IntervalId1 > 0) { newCompletionInterval1.WellCompletionIntervalId = oldWellCompObj.IntervalId1; var r = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(newCompletionInterval1); if (r < 1) { wellCompletion.Error = "Well Completion Interval could not be updated"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } if (oldWellCompObj.IntervalId1 < 1) { var r = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(newCompletionInterval1); if (r < 1) { wellCompletion.Error = "Well Completion Interval could not be updated"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } } if (wellCompletion.WellCompletionTypeId < 2) { if (wellCompletion.U1 <= 0) { wellCompletion.Error = "Please provide a valid Upper Interval"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.U1 < wellCompletion.L1 || wellCompletion.U1.Equals(wellCompletion.L1)) { wellCompletion.Error = "Please provide a valid Upper Interval"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (oldWellCompObj.IntervalId2 > 0) { var r = new WellCompletionIntervalServices().DeleteWellCompletionIntervalCheckReferences(oldWellCompObj.IntervalId2); if (!r) { wellCompletion.Error = "The process could not be completed. The requested item update will cause data loss."; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } var newCompletionInterval = new WellCompletionInterval { LowerInterval = wellCompletion.L1, UpperInterval = wellCompletion.U1, DateCompleted = wellCompletion.DateCompleted.ToString(), LastUpdatedTime = DateTime.Now.ToString("g"), WellCompletionId = oldWellCompletion.WellCompletionId }; if (oldWellCompObj.IntervalId1 > 0) { newCompletionInterval.WellCompletionIntervalId = oldWellCompObj.IntervalId1; var r = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(newCompletionInterval); if (r < 1) { wellCompletion.Error = "Well Completion Interval could not be updated"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } if (oldWellCompObj.IntervalId1 < 1) { var r = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(newCompletionInterval); if (r < 1) { wellCompletion.Error = "Well Completion Interval could not be updated"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } } var k = new WellCompletionServices().UpdateWellCompletionCheckDuplicate(oldWellCompletion); if (k < 1) { wellCompletion.Error = "Process Failed! Please contact the Admin or try again later"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } wellCompletion.Error = "Well Completion Information was successfully updated"; wellCompletion.ErrorCode = 1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletion.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; wellCompletion.ErrorCode = 0; ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddWellCompletion(WellCompletion wellCompletion) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (!ModelState.IsValid) { wellCompletion.Error = "Please supply all required well Completions and try again"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(wellCompletion); if (wx.Code < 1) { wellCompletion.Error = wx.Error; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.U1 <= 0) { wellCompletion.Error = "Please provide a valid Upper Interval"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.WellCompletionTypeId > 1) { if (wellCompletion.L2 <= 0) { wellCompletion.Error = "Please provide a valid Lower Intervalv 2"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.U2 <= 0) { wellCompletion.Error = "Please provide a valid Upper Interval 2"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } if (wellCompletion.U2 < wellCompletion.L2 || wellCompletion.U2.Equals(wellCompletion.L2)) { wellCompletion.Error = "Please provide a valid Upper Interval 2"; wellCompletion.ErrorCode = -1; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } } var k = new WellCompletionServices().AddWellCompletionCheckDuplicate(wellCompletion); if (k < 1) { if (k == -3) { wellCompletion.Error = "Well Completion already exists"; wellCompletion.ErrorCode = -3; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } wellCompletion.Error = "Process Failed! Please contact the Admin or try again later"; wellCompletion.ErrorCode = 0; return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } wellCompletion.Error = "Record was added successfully"; wellCompletion.ErrorCode = 1; wellCompletion.WellCompletionId = k; wellCompletion.DatecomPletedString = wellCompletion.DateCompleted.ToString(); return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletion.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; wellCompletion.ErrorCode = 0; ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(Json(wellCompletion, JsonRequestBehavior.AllowGet)); } }