public ActionResult FindContingency(string ProjectId) { Contingency findOne = db.Contingency.Find(ProjectId); if (findOne == null) { findOne = new Contingency(); } return(Json(findOne)); }
public void SaveContingency(string ProjectId, string ContingencyFee) { decimal?feeNullable = string.IsNullOrEmpty(ContingencyFee) ? new Nullable <decimal>() : new Decimal(Double.Parse(ContingencyFee)); Contingency findOne = db.Contingency.Find(ProjectId); if (findOne != null) { findOne.ContingencyFee = feeNullable; } else { findOne = new Contingency() { ProjectId = ProjectId, ContingencyFee = feeNullable, InDateTime = DateTime.Now, InUserId = UserInfo.UserId }; db.Contingency.Add(findOne); } db.SaveChanges(); }
// crossSegmentPointer = Path to data element followed by expected value in "[]" e.g. HLO->REF->REF01[PK] private void AddIdValue(SchemaRow segmentRow, int row, string crossSegmentPointer, List <string> optionalValues, Dictionary <string, string> allowedValues, Dictionary <string, Contingency> contingencies) { allowedValues.Add(segmentRow.EnumCode, segmentRow.EnumName); if (string.Compare(segmentRow.IgnoreFlag, "I", true) == 0 || string.Compare(segmentRow.EnumFlag, "?", true) == 0) { optionalValues.Add(segmentRow.EnumCode); } if (string.IsNullOrWhiteSpace(segmentRow.ContingencyType) == false) { segmentRow.ContingencyType = segmentRow.ContingencyType.Trim(); if (string.Compare(segmentRow.ContingencyType, "E", true) != 0 && string.Compare(segmentRow.ContingencyType, "CS", true) != 0) { AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(ContingencyTypeIndex), string.Format("Invalid contingency type {0}", segmentRow.ContingencyType)); } else { Contingency contingency = new Contingency(); if (string.Compare(segmentRow.ContingencyType, "E", true) == 0) { contingency.Type = ContingencyType.Enumeration; } else if (string.Compare(segmentRow.ContingencyType, "CS", true) == 0) { contingency.Type = ContingencyType.CrossSegment; } AddPendingContingencies(row, segmentRow.Contingencies, contingency); ResolveContingency(row, crossSegmentPointer, segmentRow.EnumCode); contingencies.Add(segmentRow.EnumCode, contingency); } } }
// here contingencyValues are row numbers private void AddPendingContingencies(int currentRow, string contingencyValues, Contingency currentRowContingency) { if (string.IsNullOrWhiteSpace(contingencyValues) == true) { AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), "No contigency specified"); return; } string[] contingencyValueArr = contingencyValues.Split(','); int[] contingencyValueRows = new int[contingencyValueArr.Length]; int contingencyRow; foreach (string contingencyValueRow in contingencyValueArr) { if (int.TryParse(contingencyValueRow.Trim(), out contingencyRow) == true) { // Check if contingency value is already present if (contingencyRow <= currentRow) { if (contingencyRow == currentRow) { AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), "Same row cannot be marked as its own contingency"); continue; } string contingencyValue = null; if (currentRowContingency.Type == ContingencyType.Enumeration && ContingencyValue.ContainsKey(contingencyRow)) { contingencyValue = ContingencyValue[contingencyRow]; } else if (currentRowContingency.Type == ContingencyType.CrossSegment && ContingencyPath.ContainsKey(contingencyRow)) { contingencyValue = ContingencyPath[contingencyRow]; } if (contingencyValue != null) { currentRowContingency.AddContingencyValue(contingencyValue); } else { AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), string.Format("Invalid contingency row {0}. Rule: Cotingency row should be marked as each other's contingency.", contingencyRow)); } } else { List <Contingency> contingencies; if (PendingContingencies.TryGetValue(contingencyRow, out contingencies) == true) { contingencies.Add(currentRowContingency); } else { contingencies = new List <Contingency>(); contingencies.Add(currentRowContingency); PendingContingencies.Add(contingencyRow, contingencies); } } } else { AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), string.Format("Invalid contingency row {0}", contingencyValueRow)); } } }
public void Setup() { _testingObject = new Contingency <ClassTest>(_path, Serializer.CSV); }
private void ValidateContingencies() { // Assumption: If id data segment is not present then this function will not report error // as we must have already reported that data segment as missing segment earlier Dictionary <string, List <IDocumentFragment> > contingencyOccurances = new Dictionary <string, List <IDocumentFragment> >(); ReadSegmentsWithIdDataTypeChildrens(contingencyOccurances, FatpipeDocumentInst.RootFragment); foreach (string path in contingencyOccurances.Keys) { // Select pluglet for current path // Selecting pluglet from the 1st documentFragment as pluglet will be // same for all documentFragments with same path IDocumentFragment documentFragment = contingencyOccurances[path][0]; IPluglet pluglet = documentFragment.Pluglet; // Pluglet will point to segment, process all child with data type as X12_IdDataType // Filter out non-mandatory data type pluglets foreach (Pluglet child in pluglet.Children) { if (child.PlugletType == PlugletType.Data && child.DataType is X12_IdDataType && child.IsMandatory == true) { List <string> presentValues = GetAllPresentValues(contingencyOccurances[path], child); X12_IdDataType dataType = child.DataType as X12_IdDataType; foreach (string allowedValue in dataType.AllowedValues.Keys) { Contingency contingencies = dataType.GetContingencies(allowedValue); // TODO: Use Ignore flag at id value level // If Id value does not have any contingency then segment with that value must exist if (contingencies == null || contingencies.ContingencyValues.Count == 0) { if (presentValues.Contains(allowedValue) == false && dataType.IsOptionalValue(allowedValue) == false) { Errors.AddSegmentError(pluglet.Tag, X12ErrorCode.DeMandatoryIdValueMissingCode , string.Format("{0} : {1}", X12ErrorCode.GetDataElementErrorDescription(X12ErrorCode.DeMandatoryIdValueMissingCode), allowedValue) , documentFragment.SequenceNumber, documentFragment.StartOffset, documentFragment.EndOffset, EdiErrorType.Error); } } // If Id value has contingencies of type Enumeration then segment with that value or any contingency value must exist else if (contingencies.Type == ContingencyType.Enumeration) { bool valuePresent = presentValues.Contains(allowedValue); if (valuePresent == false) { foreach (string alternateValue in contingencies.ContingencyValues) { valuePresent = presentValues.Contains(alternateValue); if (valuePresent) { break; } } } if (valuePresent == false) { Errors.AddSegmentError(pluglet.Tag, X12ErrorCode.DeMandatoryIdValueOrAlternativeValueMissingCode , string.Format("{0} : {1}", X12ErrorCode.GetDataElementErrorDescription(X12ErrorCode.DeMandatoryIdValueOrAlternativeValueMissingCode), allowedValue) , documentFragment.SequenceNumber, documentFragment.StartOffset, documentFragment.EndOffset, EdiErrorType.Error); } } // If contingency type is cross segment then either both values must exist or both values missing else if (contingencies.Type == ContingencyType.CrossSegment) { // TODO: handle all values in contingencies.ContingencyValues string xPath = contingencies.ContingencyValues[0]; bool currentValuePresent = presentValues.Contains(allowedValue); bool crossSegmentValuePresent = IsCrossSegmentValuePresent(contingencyOccurances, xPath, pluglet.PathSeperator); if (currentValuePresent != crossSegmentValuePresent) { Errors.AddSegmentError(pluglet.Tag, X12ErrorCode.DeCrossSegmentIdValueOccurancesDoesNotMatch , string.Format("{0} : {1} {2}", X12ErrorCode.GetDataElementErrorDescription(X12ErrorCode.DeCrossSegmentIdValueOccurancesDoesNotMatch), allowedValue, xPath) , documentFragment.SequenceNumber, documentFragment.StartOffset, documentFragment.EndOffset, EdiErrorType.Error); } } } } } } }