/// <summary> /// Sets the tolling information for a tolling letter CMO message. /// </summary> /// <param name="message">The CMO message to update.</param> /// <returns>true if the tolling information was set or cleared successfully; otherwise, false.</returns> /// <remarks>The tolling information can only be successfully set if the message is a tolling letter and cleared if the message is not a tolling letter. The information will automatically be cleared for messages that are not tolling letters regardless of the message's tolling values.</remarks> private bool SetCmoMessageTolling(CmoMessage message) { if (message == null) { return(false); } string candidateID = message.CandidateID; int messageID = message.ID; TollingLetter letter = message.TollingLetter; if (message.IsInadequateResponseLetter) { // force interpretation of inadequate response letters as tolling letters if (letter == null) { letter = message.TollingLetter = GetTollingLetter(CPConvert.ToCfisCode(AuditReportType.IdrInadequateResponse), message.IsIdrAdditionalInadequateLetter || message.IsDarAdditionalInadequateLetter ? "ADDINA" : "INARES", "INAD"); } if (!message.TollingEventNumber.HasValue) { message.TollingEventNumber = int.MinValue; } } bool hasTolling = message.TollingEventNumber.HasValue && letter != null; bool isTolling = message.IsTollingLetter; using (Data.CmoEntities context = new Data.CmoEntities()) { var tl = context.CmoTollingLetters.FirstOrDefault(l => l.CandidateId == message.CandidateID && l.MessageId == message.ID); if (tl != null) { if (isTolling) { tl.EventNumber = message.TollingEventNumber ?? int.MinValue; } else { context.DeleteObject(tl); } } else if (isTolling) { context.AddToCmoTollingLetters(Data.CmoTollingLetter.CreateCmoTollingLetter(candidateID, messageID, message.TollingEventNumber ?? int.MinValue, letter.ID)); } try { int updates = context.SaveChanges(); return(isTolling ? updates > 0 : !hasTolling); } catch (OptimisticConcurrencyException) { return(false); } } }
/// <summary> /// Updates the post election dates corresponding to a CMO post election audit message in CFIS. /// </summary> /// <param name="message">The post election audit message to update.</param> /// <returns>true if the post election dates were successfully updated in CFIS; otherwise, false.</returns> private bool UpdatePostElectionDates(CmoMessage message) { if (message == null) { return(false); } AuditReportType type; if (message.IsInitialDocumentationRequest) { type = AuditReportType.InitialDocumentationRequest; } else if (message.IsIdrInadequateResponseLetter) { type = AuditReportType.IdrInadequateResponse; } else if (message.IsIdrAdditionalInadequateLetter) { type = AuditReportType.IdrAdditionalInadequateResponse; } else if (message.IsDarInadequateResponseLetter) { type = AuditReportType.DarInadequateResponse; } else if (message.IsDarAdditionalInadequateLetter) { type = AuditReportType.DarAdditionalInadequateResponse; } else { return(false); } using (PostElectionTableAdapter ta = new PostElectionTableAdapter()) { object retObj; // SQL error code as object int retVal; // SQL error code int? eventNumber = message.TollingEventNumber; // number of event generated or source tolling event, as appropriate retObj = ta.UpdatePostElectionDates(message.CandidateID, message.ElectionCycle, CPConvert.ToCfisCode(type), message.PostElectionAuditRequestType == AuditRequestType.SecondRequest || message.PostElectionAuditRequestType == AuditRequestType.SecondRepost ? "Y" : "N", ref eventNumber); if (retObj != null && int.TryParse(retObj.ToString(), out retVal)) { if (retVal == 0) { // save event number for tolling letters if (eventNumber.HasValue && message.IsTollingLetter) { message.TollingEventNumber = eventNumber; SetCmoMessageTolling(message); } return(true); } } return(false); } }