public ActionResult CreateNewFormResultFull(string formId, string enterprise_id, string group_id, string subject, string interviewer) { def_FormResults frmRes = FormResults.CreateNewFormResultModel(formId); // Add the FKs if (!String.IsNullOrEmpty(enterprise_id)) { frmRes.EnterpriseID = Convert.ToInt32(enterprise_id); } if (!String.IsNullOrEmpty(group_id)) { frmRes.GroupID = Convert.ToInt32(group_id); } if (!String.IsNullOrEmpty(subject)) { frmRes.subject = Convert.ToInt32(subject); } if (!String.IsNullOrEmpty(interviewer)) { frmRes.interviewer = Convert.ToInt32(interviewer); } ContentResult result = new ContentResult(); try { int formRsltId = formsRepo.AddFormResult(frmRes); result.Content = formRsltId.ToString(); } catch (Exception excptn) { Debug.WriteLine("Defws.CreateNewFormResultFull exception:" + excptn.Message); } return(result); // return the FormResult id just added }
public void PopulateItemsFromPreviousApplication(def_FormResults formResult, List <ItemToPrepopulate> itemsToPrepopulate) { if (formResult == null) { return; } if (itemsToPrepopulate == null || itemsToPrepopulate.Count == 0) { return; } def_FormResults previousFormResult = formsRepo.GetFormResultsByFormId(formResult.formId) .Where(q => q.subject == formResult.subject && q.formResultId != formResult.formResultId) .OrderByDescending(q => q.dateUpdated) .FirstOrDefault(); if (previousFormResult == null) { return; } PopulateItems(formResult, previousFormResult, itemsToPrepopulate); }
private void Upload_ProcessSectionsNode(XmlNode sectionsNode, def_FormResults formResult) { foreach (XmlNode sectionsChildNode in sectionsNode) { switch (sectionsChildNode.Name) { case "Section": int sectionNum = getIntAttribute(sectionsChildNode, "SectionNum"); XmlAttribute partAttr = sectionsChildNode.Attributes["Part"]; if (partAttr == null) { Debug.WriteLine("missing attribite \"Part\" in section node (skipping): " + getNodePath(sectionsChildNode)); continue; } string sectionPartLetter = partAttr.Value; XmlAttribute descAttr = sectionsChildNode.Attributes["Description"]; bool oldFormat = false; //data exported from the old system has a wierd description attribute for each section if (descAttr != null && descAttr.Value.StartsWith("AAMR")) { oldFormat = true; sectionNum = mapOldSectionNumToNewSystem(sectionNum); if (sectionNum == 3) { sectionPartLetter = "A"; } } Upload_ProcessSingleSectionNode(sectionsChildNode, sectionNum, sectionPartLetter, formResult, oldFormat); break; default: Debug.WriteLine("Unrecognized sections child node \"" + sectionsChildNode.Name + "\""); break; } } }
public void PopulateItemsFromEligibilityDashboard(def_FormResults formResult, List <ItemToPrepopulate> itemsToPrepopulate) { if (formResult == null) { return; } if (itemsToPrepopulate == null || itemsToPrepopulate.Count == 0) { return; } //Get Eligibility Dashboard form response def_FormResults eligibilityDashboardFormResult = formsRepo.GetFormResultsByFormId(Assmnts.Constants.CAADAP.CA_ADAP_DASHBOARD_FORM_ID) .Where(x => x.subject == formResult.subject) .OrderByDescending(x => x.dateUpdated) .FirstOrDefault(); if (eligibilityDashboardFormResult == null) { return; } PopulateItems(formResult, eligibilityDashboardFormResult, itemsToPrepopulate); }
public FileContentResult GetCsv() { string paramFormResultId = Request["formResultId"] as string; Debug.WriteLine("* * * ExportController GetCsv formResultId: " + paramFormResultId); // Get all the itemVariable's in Assessment order // Write out the initial field name (identifier) record // Get the Item responses // Get the associated ResponseVariables // Write it out to CSV int formResultId = Convert.ToInt32(paramFormResultId); def_FormResults frmRes = formsRepo.GetFormResultById(formResultId); def_Forms frm = formsRepo.GetFormById(frmRes.formId); List <def_Parts> parts = formsRepo.GetFormParts(frm); // return new FileStreamResult(fileStream, "text/csv") { FileDownloadName = fileDownloadName }; StringWriter sw = new StringWriter(); sw.WriteLine("FirstName, LastName, NickName"); sw.WriteLine("Charlie, Chaplin, Chuckles"); return(File(new System.Text.UTF8Encoding().GetBytes(sw.ToString()), "text/csv", "SisAssmnt.csv")); }
private def_FormResults CreateNewBlankStubApp(string ramsellId, def_FormResults previousApp) { int?subjectUserId = previousApp == null ? null : previousApp.subject; return(new def_FormResults() { formId = stubForm.formId, formStatus = 0, sessionStatus = 0, dateUpdated = DateTime.Now, deleted = false, locked = false, archived = false, EnterpriseID = SessionHelper.LoginStatus.EnterpriseID, GroupID = 0, subject = subjectUserId, interviewer = SessionHelper.LoginStatus.UserID, assigned = SessionHelper.LoginStatus.UserID, training = false, reviewStatus = 0, statusChangeDate = DateTime.Now }); }
public static def_FormResults CreateNewFormResultFull(string formId, string enterprise_id, string group_id, string subject, string interviewer) { def_FormResults frmRes = null; try { frmRes = FormResults.CreateNewFormResultModel(formId); // Add the FKs if (!String.IsNullOrEmpty(enterprise_id)) { frmRes.EnterpriseID = Convert.ToInt32(enterprise_id); } if (!String.IsNullOrEmpty(group_id)) { frmRes.GroupID = Convert.ToInt32(group_id); } if (!String.IsNullOrEmpty(subject)) { frmRes.subject = Convert.ToInt32(subject); } if (!String.IsNullOrEmpty(interviewer)) { frmRes.interviewer = Convert.ToInt32(interviewer); } } catch (Exception xcptn) { Debug.WriteLine("CreateNewFormResultFull formId: " + formId + " " + xcptn.Message); } return(frmRes); }
// Form Results /// <summary> /// Add and Save a FormResults records to the SQL table. /// </summary> /// <param name="frmRslt">FormResults object</param> /// <returns>Returns the formResultId of the record INSERTed</returns> public int AddFormResult(def_FormResults frmRslt) { try { db.def_FormResults.Add(frmRslt); db.SaveChanges(); } catch (DbEntityValidationException xptn) { Debug.WriteLine("* * * FormsRepository AddFormResult Exception: " + xptn.Message); foreach (var evnt in xptn.EntityValidationErrors) { Debug.WriteLine(@"Entity of type '{0}' in state '{1}' has the following validation errors:", evnt.Entry.Entity.GetType().Name, evnt.Entry.State); foreach (var ve in evnt.ValidationErrors) { Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(frmRslt.formResultId); }
private void CheckAndRemoveCaseManager() { IQueryable <def_FormResults> frs = formsRepo.GetFormResultsByFormId(11).Where(fr => fr.interviewer == SessionHelper.LoginStatus.UserID); List <int> users = new List <int>(); using (var uasContext = Data.Concrete.DataContext.getUasDbContext()) { users = (from u in uasContext.uas_User where u.ManagerID == SessionHelper.LoginStatus.UserID select u.UserID).ToList(); } List <int> invalidFormResults = (from fr in frs where !users.Any(u => u == fr.subject) select fr.formResultId).ToList(); foreach (int formResultId in invalidFormResults) { def_FormResults fr = formsRepo.GetFormResultById(formResultId); fr.interviewer = fr.subject; formsRepo.SaveFormResults(fr); } }
public bool UploadCheck(FormCollection formCollection) { bool newFile = true; int RelatedEnumId = formsRepo.GetRelatedEnumIdByEnumDescription("formResultId"); int AttachTypeId = formsRepo.GetAttachTypeIdByAttachDescription("Generic Upload"); string data = Request["arrayData"]; int formResultId = Convert.ToInt32(formCollection["formResultId"]); System.Web.HttpPostedFileWrapper file = (System.Web.HttpPostedFileWrapper)Request.Files["file" + formResultId.ToString()]; def_FormResults fr = formsRepo.GetFormResultById(formResultId); Dictionary <int, string> texts = FileUploads.RetrieveFileDisplayTextsByRelatedId(formsRepo, formResultId, RelatedEnumId, "A", AttachTypeId); foreach (int k in texts.Keys) { if (file.FileName.Equals(texts[k])) { newFile = false; } } return(newFile); }
public void SaveFormResults(def_FormResults frmRes) { formsRepo.SaveFormResults(frmRes); }
public ActionResult ShowEligibility() { if (!SessionHelper.IsUserLoggedIn) { return(RedirectToAction("Index", "Account", null)); } if (SessionHelper.SessionForm == null) { SessionHelper.SessionForm = new SessionForm(); } // retrieve and set SessionForm params string formIdent = "CA-ADAP-DASHBOARD", entName = "California"; def_Forms frm = formsRepo.GetFormByIdentifier(formIdent); Enterprise ent = new AuthenticationClient().GetEnterpriseByName(entName); if (frm == null) { return(Content("Could not find form with identifier \"" + formIdent + "\"")); } if (ent == null) { return(Content("Could not find enterprise with name \"" + entName + "\"")); } // Get the FormResult to get the subject of the current Application def_FormResults fr = formsRepo.GetFormResultById(SessionHelper.SessionForm.formResultId); if (fr == null) { return(Content("Could not find the current Application \"" + SessionHelper.SessionForm.formResultId.ToString() + "\"")); } // Get the Eligibility Form for the subject IEnumerable <def_FormResults> frElgList = formsRepo.GetFormResultsByFormSubject(frm.formId, fr.subject); def_FormResults frElg = null; if ((frElgList == null) || frElgList.Count <def_FormResults>() == 0) { mLogger.Debug("Couldn't find a current FormResult for Eligibility. Create one."); frElg = new def_FormResults() { formId = frm.formId, formStatus = 0, sessionStatus = 0, dateUpdated = DateTime.Now, deleted = false, locked = false, archived = false, EnterpriseID = ent.EnterpriseID, GroupID = fr.GroupID, // User the same Enrollment Center subject = fr.subject, interviewer = fr.interviewer, assigned = fr.assigned, training = false, reviewStatus = 0, statusChangeDate = DateTime.Now, LastModifiedByUserId = fr.LastModifiedByUserId }; AuthenticationClient authClient = new AuthenticationClient(); var groupIds = authClient.GetGroupsInUserPermissions(SessionHelper.LoginStatus.EnterpriseID, SessionHelper.LoginStatus.UserID).Select(x => x.GroupID); var groupId = groupIds.FirstOrDefault(); Dictionary <string, string> uasItemDictionary = new Dictionary <string, string>(); var uasData = authClient.GetUser(fr.subject.Value); var adapId = authClient.GetExistingAdapIdentifier(uasData.UserID, uasData.EnterpriseID); // ADAP ID if (!String.IsNullOrWhiteSpace(adapId)) { uasItemDictionary.Add("C1_MemberIdentifier_item", adapId); } Applications appl = new Applications(formsRepo); //Populate from UAS //Populate items where Source = UAS in json file frElg = appl.CreateFormResultPopulatedFromUAS(SessionHelper.LoginStatus.EnterpriseID, groupId, uasData.UserID, frm.formId, uasItemDictionary); int newFrmRsltId = formsRepo.AddFormResult(frElg); mLogger.Debug("New Eligibility FormResult created: {0}", newFrmRsltId); } else { frElg = frElgList.First <def_FormResults>(); } SessionHelper.SessionForm.formId = frElg.formId; SessionHelper.SessionForm.formResultId = frElg.formResultId; SessionHelper.SessionForm.formIdentifier = formIdent; // SessionHelper.LoginStatus.EnterpriseID = ent.EnterpriseID; def_Parts prt = formsRepo.GetFormParts(frm)[0]; SessionHelper.SessionForm.partId = prt.partId; Session["part"] = prt.partId.ToString(); def_Sections sct = formsRepo.GetSectionsInPart(prt)[1]; Session["section"] = sct.sectionId.ToString(); return(RedirectToAction("Template", "Results", new { sectionId = sct.sectionId.ToString(), partId = SessionHelper.SessionForm.partId.ToString() })); }
public void CreateElgibility(int formResultId) { string formIdent = "CA-ADAP-DASHBOARD", entName = "California"; def_Forms frm = formsRepo.GetFormByIdentifier(formIdent); Enterprise ent = new AuthenticationClient().GetEnterpriseByName(entName); // Get the FormResult to get the subject of the current Application def_FormResults fr = formsRepo.GetFormResultById(formResultId); // Get the Eligibility Form for the subject IEnumerable <def_FormResults> frElgList = formsRepo.GetFormResultsByFormSubject(frm.formId, fr.subject); def_FormResults frmRes = null; if ((frElgList == null) || frElgList.Count <def_FormResults>() == 0) { mLogger.Debug("Couldn't find a current FormResult for Eligibility. Create one."); frmRes = new def_FormResults() { formId = frm.formId, formStatus = 0, sessionStatus = 0, dateUpdated = DateTime.Now, deleted = false, locked = false, archived = false, EnterpriseID = ent.EnterpriseID, GroupID = fr.GroupID, // User the same Enrollment Center subject = fr.subject, interviewer = fr.interviewer, assigned = fr.assigned, training = false, reviewStatus = 0, statusChangeDate = DateTime.Now, LastModifiedByUserId = fr.LastModifiedByUserId }; int newFrmRsltId = formsRepo.AddFormResult(frmRes); mLogger.Debug("New Eligibility FormResult created: {0}", newFrmRsltId); } else { frmRes = frElgList.First <def_FormResults>(); } // make sure item responses exist for the form Dictionary <string, string> DataToPopulate = new Dictionary <string, string>(); var sectionItems = formsRepo.GetSectionItemsBySectionId(756); AuthenticationClient authClient = new AuthenticationClient(); var uasData = authClient.GetUser(fr.subject.Value); var adapId = authClient.GetADAPIdentifier(uasData.UserID, uasData.EnterpriseID); foreach (var item in sectionItems) { var defItem = formsRepo.GetItemById(item.itemId); if (defItem.identifier == "C1_MemberIdentifier_item") { DataToPopulate.Add(defItem.identifier, adapId); } else if (defItem.identifier == "C1_MemberFirstName_item") { def_ResponseVariables firstName = formsRepo.GetResponseVariablesBySubjectForm(fr.subject.Value, 15, "C1_MemberFirstName"); DataToPopulate.Add(defItem.identifier, firstName != null ? firstName.rspValue : string.Empty); } else if (defItem.identifier == "C1_MemberLastName_item") { def_ResponseVariables lastName = formsRepo.GetResponseVariablesBySubjectForm(fr.subject.Value, 15, "C1_MemberLastName"); DataToPopulate.Add(defItem.identifier, lastName != null ? lastName.rspValue : string.Empty); } else if (defItem.identifier == "C1_MemberDateOfBirth_item") { def_ResponseVariables dob = formsRepo.GetResponseVariablesBySubjectForm(fr.subject.Value, 15, "C1_MemberDateOfBirth"); DataToPopulate.Add(defItem.identifier, dob != null ? dob.rspValue : string.Empty); } else { DataToPopulate.Add(defItem.identifier, string.Empty); } } foreach (String s in DataToPopulate.Keys) { def_Items item = formsRepo.GetItemByIdentifier(s); def_ItemResults ir = new def_ItemResults() { itemId = item.itemId, sessionStatus = 0, dateUpdated = DateTime.Now }; // check if the key already exist var itemResult = formsRepo.GetItemResultByFormResItem(frmRes.formResultId, item.itemId); if (itemResult == null) { frmRes.def_ItemResults.Add(ir); foreach (var iv in formsRepo.GetItemVariablesByItemId(item.itemId)) { // Note for General forms like ADAP there should only be 1 ItemVariable per Item def_ResponseVariables rv = new def_ResponseVariables(); rv.itemVariableId = iv.itemVariableId; // rv.rspDate = DateTime.Now; // RRB 11/11/15 The date, fp, and int fields are for the native data conversion. rv.rspValue = DataToPopulate[s]; formsRepo.ConvertValueToNativeType(iv, rv); ir.def_ResponseVariables.Add(rv); } } else { ir = itemResult; } } formsRepo.Save(); }
public static void TransformAndAppendResponseNodesToXML( XmlNode appendTo, XmlDocument doc, DefResponseElement rspElement, int formResultId, IFormsRepository formsRepo) { string elementContent = null; //super-special case for Enrollment_Type, which is based on the formStatus, rather than responses if (rspElement.tagName == "Enrollment_Type") { #region check the formResult.formStatus field to determin enrollment type def_FormResults fr = formsRepo.GetFormResultById(formResultId); def_StatusMaster statusMaster = formsRepo.GetStatusMasterByFormId(fr.formId); def_StatusDetail statusDetail = formsRepo.GetStatusDetailBySortOrder(statusMaster.statusMasterId, fr.formStatus); switch (statusDetail.identifier) { case "NEEDS_INFORMATION": elementContent = "2"; break; case "APPROVED": elementContent = "2"; break; default: elementContent = "1"; break; } #endregion } if (rspElement.tagName == "Email") { #region check uas tables for email using (UASEntities context = Data.Concrete.DataContext.getUasDbContext()) { def_FormResults fr = formsRepo.GetFormResultById(formResultId); var data = from ue in context.uas_UserEmail where ue.UserID == fr.subject && ue.EmailAddress != null && ue.MayContact orderby ue.SortOrder select ue.EmailAddress; elementContent = data.FirstOrDefault(); } #endregion } if (rspElement.tagName == "Mailing_Address" || rspElement.tagName == "Mailing_City" || rspElement.tagName == "Mailing_State" || rspElement.tagName == "Mailing_Zip") { def_ResponseVariables rv = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, "ADAP_C2_SameAsMailing"); if (rv.rspInt != null && rv.rspInt == 1) { return; } } //assign a special-case transformation value if applicable if (elementContent == null) { elementContent = RamsellTransformations.GetExportValueForRamsellTag(rspElement.tagName, formResultId, formsRepo); } //if elementContent has been assigned a non-null value, //it must have been assigned to handle a one-off special case (above), //so append one node with elementContent and terminate this function if (elementContent != null) { AppendContentNodeToXML(appendTo, doc, rspElement.tagName, elementContent); return; } #region normal case: append an xml node for each associated itemvariable identifier in ramsellIdentifierMap List <string> ivIdentList = GetItemVariableIdentifiersForRamsellTagName(rspElement.tagName); foreach (string ivIdent in ivIdentList) { def_ResponseVariables rv = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, ivIdent); if ((rv != null) && !String.IsNullOrWhiteSpace(rv.rspValue)) { elementContent = GetFormattedResponse(rv, rspElement.xmlType, formsRepo); } else { GetDefaultValue(rspElement.xmlType); // to pass validation } //if there are multiple itemVariables, assume this is one out of a set of checkboxes //in which case zeroes represent unchecked checkboxes which should be ignored if ((elementContent == "0") && (ivIdentList.Count > 1)) { continue; } // if no output and the tag is optional, don't write it out // *** For some reason Ramsell system doesn't seem process empty tags or recognize as valid // *** Even though they pass XML / XSD validation if (String.IsNullOrWhiteSpace(elementContent) && rspElement.minOccurs.Equals(0.0m)) { continue; } AppendContentNodeToXML(appendTo, doc, rspElement.tagName, elementContent); } #endregion }
private void Upload_SaveResponseVariable(string itmVarIdentifier, string rspVal, def_FormResults fr) { if (String.IsNullOrWhiteSpace(rspVal)) { return; } Debug.WriteLine("sving identifier/value: " + itmVarIdentifier + " -> " + rspVal); def_ItemVariables iv = GetItemVariableByIdentifier(itmVarIdentifier); if (iv == null) { Debug.WriteLine("could not find item variable with identifier \"" + itmVarIdentifier + "\" (not case-sensitive)"); return; } //delete any existing response for this formResult+itemVariable def_ResponseVariables existingRv = formsRepo.GetResponseVariablesByFormResultItemVarId(fr.formResultId, iv.itemVariableId); if (existingRv != null) { formsRepo.DeleteResponseVariableNoSave(existingRv); } //for response values that reresent dates, convert them to the new format try { if (iv.baseTypeId == 3) { rspVal = convertOldToNewDate(rspVal); } } catch (DateNotSupportedException dnse) { Debug.WriteLine("found date prior to 1900 in response for item variable \"" + itmVarIdentifier + "\", skipping..."); return; } // if (itmVarIdentifier.Equals("sis_cl_attend")) { switch (rspVal) { case "All Of": rspVal = "1"; break; case "Part Of": rspVal = "2"; break; case "Did Not": rspVal = "3"; break; } } def_ItemResults ir = fr.def_ItemResults.Where(r => r.itemId == iv.itemId).FirstOrDefault();//formsRepo.GetItemResultByFormResItem(formRsltId, iv.itemId); //int itemResultId; if (ir == null) { ir = new def_ItemResults(); //ir.formResultId = formRsltId; ir.itemId = iv.itemId; ir.sessionStatus = 0; ir.dateUpdated = DateTime.Now; fr.def_ItemResults.Add(ir); //try{ // itemResultId = formsRepo.AddItemResult(ir); //} //catch (Exception e) //{ // return; // Debug.WriteLine("error while adding item result! ItemVariable Identifier: \"{0}\", response value: \"{1}\", formResultId: \"{2}\"", itmVarIdentifier, rspVal, formRsltId); //} } //else //{ // itemResultId = ir.itemResultId; //} //if there is already a response variable for this itemvariable, return //if (ir.def_ResponseVariables.Where(v => v.itemVariableId == iv.itemVariableId).Any()) // return; def_ResponseVariables rv = new def_ResponseVariables { //itemResultId = itemResultId, itemVariableId = iv.itemVariableId, rspValue = rspVal }; try { formsRepo.ConvertValueToNativeType(iv, rv); } catch (Exception e) { Debug.WriteLine("For item variable \"{0}\", Unable to convert value \"{1}\" to native type (baseTypeId {2})", iv.identifier, rspVal, iv.baseTypeId); return; } ir.def_ResponseVariables.Add(rv); //try //{ // formsRepo.AddResponseVariable(rv); //} //catch (Exception e) //{ // Debug.WriteLine("error while adding response variable! ItemVariable Identifier: \"{0}\", response value: \"{1}\", formResultId: \"{2}\"", itmVarIdentifier, rspVal, formRsltId); //} //formsRepo.Save(); }
private void Upload_ProcessItemNode(XmlNode itemNode, def_FormResults formResult) { switch (itemNode.Name) { case "SitChanged": case "Upload_Info": break; case "SubscriptionID": //groupId is hard-coded now //alternatively we could look it up using the commented code below //int oldSystemSubId = -1; //try //{ // oldSystemSubId = Convert.ToInt32(itemNode.InnerText); //} //catch (Exception e){} //if (oldSystemSubId < 0) //{ // Debug.WriteLine("SubscriptionID node: could not parse valid old-system subscription id from string \"" + itemNode.InnerText + "\", setting GroupID to 0"); // formResult.GroupID = 0; // break; //} //try //{ // formResult.GroupID = MapOldToNewGroupId(oldSystemSubId, formResult.EnterpriseID.Value ); //} //catch (Exception e) //{ // Debug.WriteLine("SubscriptionID node: could not map old-system susbscription id " + oldSystemSubId + " to a new-system GroupID, setting GroupID to 0"); // formResult.GroupID = 0; //} break; case "InterviewerUserId": UasServiceRef.User interviewer = auth.GetUserByLoginID(itemNode.InnerText); if (interviewer == null) { Debug.WriteLine("InterviewerUserId node: Could not find user with loginID \"" + itemNode.InnerText + "\", setting interviewer to 0"); formResult.interviewer = 0; } else { formResult.interviewer = interviewer.UserID; } break; case "UserID": UasServiceRef.User assigned = auth.GetUserByLoginID(itemNode.InnerText); if (assigned == null) { Debug.WriteLine("UserID node: Could not find user with loginID \"" + itemNode.InnerText + "\", setting assigned to 0"); formResult.assigned = 0; } else { formResult.assigned = assigned.UserID; } break; case "Training": formResult.training = Convert.ToBoolean(itemNode.InnerText); break; case "ReviewStatus": formResult.reviewStatus = Convert.ToByte(itemNode.InnerText); break; case "SIS_StatusChangeDate": formResult.statusChangeDate = Convert.ToDateTime(itemNode.InnerText); break; case "SIS_STATUS": formResult.formStatus = Convert.ToByte(itemNode.InnerText); break; case "sis_archived": formResult.archived = Convert.ToBoolean(itemNode.InnerText); break; //normal case (for items that corespond to itemVariables i the new system) default: string itmVarIdentifier = convertToNewIdentifier(itemNode.Name); string rspVal = itemNode.InnerText; Upload_SaveResponseVariable(itmVarIdentifier, rspVal, formResult); break; } }
private int GetNewFormResultID(int formResultId) { Debug.WriteLine("DataSync.GetNewFormResultID formResultId: " + formResultId.ToString()); def_FormResults fr = formsRepo.GetFormResultById(formResultId); try { HttpWebRequest httpRequest = null; httpRequest = (HttpWebRequest)WebRequest.Create(sisOnlineURL + @"Defws/Login?UserId=" + SessionHelper.LoginInfo.LoginID + "&pwrd=" + SessionHelper.LoginInfo.Password); CookieContainer cc = new CookieContainer(); httpRequest.CookieContainer = cc; httpRequest.Method = WebRequestMethods.Http.Get; // Get back the HTTP response for web server using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse()) { using (Stream httpResponseStream = httpResponse.GetResponseStream()) { string response = String.Empty; using (StreamReader reader = new StreamReader(httpResponseStream)) { response = reader.ReadToEnd(); } Debug.WriteLine("GetNewFormResultID response: " + response); } } using (var client = new CookieWebClient(cc)) { var data = new NameValueCollection() { //int formId, int formStatus, int EnterpriseID, int GroupID, int interviewer) // int formId, int formStatus, int sessionStatus, DateTime dateUpdated, // bool deleted, bool locked, bool archived, int EnterpriseID, int GroupID, int subject, int interviewer, int assigned, bool training, int reviewStatus, DateTime statusChangeDate) { "formId", fr.formId.ToString() }, { "formStatus", fr.formStatus.ToString() }, { "sessionStatus", fr.sessionStatus.ToString() }, { "dateUpdated", fr.dateUpdated.ToString() }, { "deleted", fr.deleted.ToString() }, { "locked", fr.locked.ToString() }, { "archived", fr.archived.ToString() }, { "EnterpriseID", fr.EnterpriseID.ToString() }, { "GroupID", fr.GroupID.ToString() }, { "subject", fr.subject.ToString() }, { "interviewer", fr.interviewer.ToString() }, { "assigned", fr.assigned.ToString() }, { "training", fr.training.ToString() }, { "reviewStatus", fr.reviewStatus.ToString() }, { "statusChangeDate", fr.statusChangeDate.ToString() } }; byte[] result = client.UploadValues(sisOnlineURL + "DataSync/" + "CreateFormResult", "POST", data); string newId = Encoding.ASCII.GetString(result); int newFormResultId = Int32.Parse(newId); SessionHelper.Write("newFormResultId", newFormResultId); return(newFormResultId); } } catch (Exception ex) { Debug.WriteLine("GetNewFormResultID - exception:" + ex.Message); return(formResultId); } }
private static void AddHiddenFields(IFormsRepository formsRepo, def_FormResults oldFormResult, def_FormResults copyFormResult) { string version = GetVersion(formsRepo, oldFormResult); // Increment version -- may add more complex function here to do this later, right now just increment by 1 each time string newVersion = (Int32.Parse(version) + 1).ToString(); Updates.AddField(formsRepo, Updates.SIS_HIDDEN, oldFormResult, Updates.RELATED_FORM_RESULT, copyFormResult.formResultId.ToString()); Updates.AddField(formsRepo, Updates.SIS_HIDDEN, copyFormResult, Updates.RELATED_FORM_RESULT, oldFormResult.formResultId.ToString()); Updates.AddField(formsRepo, Updates.SIS_HIDDEN, oldFormResult, Updates.VERSION, newVersion); Updates.AddField(formsRepo, Updates.SIS_HIDDEN, copyFormResult, Updates.VERSION, version); }
public ActionResult UploadCsvGetStubRecords() { string result = "USE [forms]\nGO\nSET IDENTITY_INSERT [dbo].[def_FormResults] ON\nGO\n"; using (var csvr = new CsvReader(new StreamReader(Request.InputStream))) { csvr.ReadHeaderRecord(); //organize csv headers into a heirarchy similar to the response data schema //So for each ItemId, we have a set of ItemVariableIDs, each with one csvHeader. Dictionary <int, Dictionary <int, string> > csvHeadersByIvByItem = new Dictionary <int, Dictionary <int, string> >(); foreach (string csvHeader in csvr.HeaderRecord) { string ivIdent = getItemVariableIdentifierFromCsvHeader(csvHeader); def_ItemVariables iv = formsRepo.GetItemVariableByIdentifier(ivIdent); if (iv == null) { continue; } int itmId = iv.itemId; if (!csvHeadersByIvByItem.ContainsKey(itmId)) { csvHeadersByIvByItem.Add(itmId, new Dictionary <int, string>()); } csvHeadersByIvByItem[itmId].Add(iv.itemVariableId, csvHeader); } ////determine which header is present for assigning uploaded formResults to groups //bool useOrgNames; //if( csvr.HeaderRecord.Contains( "sub_id" ) ) // useOrgNames = false; //else if (csvr.HeaderRecord.Contains("org_name")) // useOrgNames = true; //else // throw new Exception( "Could not find any headers to link assessments to groups" ); //iterate through the uploaded csv rows while (csvr.HasMoreRecords) { AssmntRecord acl = new AssmntRecord(csvr.ReadDataRecord()); int formId = 1; int subject = 0;// acl.getInt("ClientId"); int entId = acl.getInt("ent_id"); //int groupId = 460;//one-off 9/2/15//////////////////////////////// //if (useOrgNames) //{ // string orgName = acl["org_name"]; // Group group = auth.GetGroupsByGroupNameAndEnterpriseID(orgName, entId).FirstOrDefault(); // if (group == null) // throw new Exception("could not find group for org_name \"" + orgName + "\""); // groupId = group.GroupID; //} //else //{ int groupId = acl.getInt("sub_id"); //} //add new form result in database //int formRsltId = formsRepo.AddFormResult(formResult); int formRsltId = acl.getInt("sis_id"); def_FormResults formResult = formsRepo.GetFormResultById(formRsltId); // if the formResult doesn't already exist, append to the sql script for identity-inserting stub records if (formResult == null) { def_FormResults fr = new def_FormResults(); fr.formId = formId; fr.EnterpriseID = entId; fr.GroupID = groupId; fr.subject = subject; fr.dateUpdated = DateTime.Now; fr.formStatus = GetStatus(acl["Status"]); fr.locked = GetLocked(acl["Status"]); fr.sessionStatus = 0; fr.reviewStatus = 255; fr.training = false; string sql = "INSERT INTO [dbo].[def_FormResults]([formResultId],[formId],[formStatus],[sessionStatus],[dateUpdated],[deleted],[locked]," + "[archived],[EnterpriseID],[GroupID],[subject],[interviewer],[assigned],[training],[reviewStatus],[statusChangeDate])\n" + "VALUES( '" + formRsltId + "','" + fr.formId + "','" + fr.formStatus + "','" + fr.sessionStatus + "','" + fr.dateUpdated + "','" + fr.deleted + "','" + fr.locked + "','" + fr.archived + "','" + fr.EnterpriseID + "','" + fr.GroupID + "','" + fr.subject + "','" + fr.interviewer + "','" + fr.assigned + "','" + fr.training + "','" + fr.reviewStatus + "','" + fr.statusChangeDate + "')\n"; result += sql; } // // Null out the locally allocated objects so the garbage collector disposes of them. // fr = null; // acl = null; // formResult = null; //} ////saveAssessmentScript(formResult); //formsRepo.SaveFormResults(formResult); //formsRepo.GetContext().Dispose(); //formsRepo = new FormsRepository(); //// Null out the locally allocated objects so the garbage collector disposes of them. //fr = null; //acl = null; //formResult = null; } } result += "SET IDENTITY_INSERT [dbo].[def_FormResults] OFF\nGO\n"; return(Content(result)); }
public ActionResult Upload() { XmlDocument doc = new XmlDocument(); using (var sr = new StreamReader(Request.InputStream)) { string docInput = sr.ReadToEnd(); doc.LoadXml(docInput); } // Since there is a CDATA in SOAP, may need to get the // sis:data node and stream or string that into XML Document // or it appears that SOAP Formatter may do this for you. //XmlNode nodeSisData = doc.GetElementsByTagName("sis:data")[0]; //XmlDocument assmntsDoc = new XmlDocument(); //assmntsDoc.LoadXml(nodeSisData.InnerText); //Find the node from XML document with name Assessments XmlNode nodeAssmnts = doc.GetElementsByTagName("data")[0].ChildNodes[0]; //XmlNode nodeAssmnts = assmntsDoc.GetElementsByTagName("Assessments")[0]; //Loop through the child nodes (Assessment tags - there can be multiple) foreach (XmlNode assmntNode in nodeAssmnts.ChildNodes) { if ((assmntNode).NodeType == XmlNodeType.Element) { int subject = getIntAttribute(assmntNode, "ClientId"); //getIntAttribute(assmntNode, "subject"); int groupId = 93; // getIntAttribute(assmntNode, "GroupID"); int entId = 20; // getIntAttribute(assmntNode, "EnterpriseID"); int formId = 1; // getIntAttribute(assmntNode, "formId"); //add new form result in database def_FormResults formResult = new def_FormResults(); formResult.formId = formId; formResult.EnterpriseID = entId; formResult.GroupID = groupId; formResult.subject = subject; formResult.dateUpdated = DateTime.Now; formResult.formStatus = 0; formResult.sessionStatus = 0; formResult.reviewStatus = 0; formResult.training = false; int formRsltId = formsRepo.AddFormResult(formResult); formResult = formsRepo.GetFormResultById(formRsltId); foreach (XmlNode assmntChildNode in assmntNode.ChildNodes) { switch (assmntChildNode.Name) { case "Profile": Upload_ProcessProfileNode(assmntChildNode, formResult); break; case "Sections": Upload_ProcessSectionsNode(assmntChildNode, formResult); break; default: Debug.WriteLine("Unrecognized assessment child node \"" + assmntChildNode.Name + "\""); break; } } //form results are typically changed in Upload_ProcessProfileNode above formsRepo.SaveFormResults(formResult); } } return(Content("Upload Successful!")); }
public ActionResult GoAction(FormCollection formCollection) { string recId = formCollection["recId"]; string paramFormResultId = formCollection["sisId"]; string paramFormId = formCollection["formId"]; string category = formCollection["CategoryID"]; SearchModel model = new SearchModel(); if (SessionHelper.SessionForm == null) { // return RedirectToAction("Index", "Search", null); SessionHelper.SessionForm = new SessionForm(); } SessionForm sf = SessionHelper.SessionForm; if (String.IsNullOrWhiteSpace(category)) { return(RedirectToAction("Index", "Search")); } else if (category.ToLower().Equals("edit") && model.edit) { // retrieve and set SessionForm params sf.formId = Convert.ToInt32(paramFormId); sf.formResultId = Convert.ToInt32(paramFormResultId); def_FormResults formResult = formsRepo.GetFormResultById(sf.formResultId); if (!formResult.locked || (formResult.locked && model.editLocked)) { // get the sectionId of the first section of the first part based on the formId def_Forms frm = formsRepo.GetFormById(sf.formId); def_Parts prt = formsRepo.GetFormParts(frm)[0]; sf.partId = prt.partId; Session["part"] = prt.partId; def_Sections sct = formsRepo.GetSectionsInPart(prt)[0]; if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, sf.formResultId, (int)AccessLogging.accessLogFunctions.EDIT, "Initiate editing of assessment."); } return(RedirectToAction("Template", "Results", new { sectionId = sct.sectionId.ToString(), partId = sf.partId.ToString() })); } } else if (category.ToLower().Equals("review")) { // retrieve and set SessionForm params sf.formId = Convert.ToInt32(paramFormId); sf.formResultId = Convert.ToInt32(paramFormResultId); def_FormResults formResult = formsRepo.GetFormResultById(sf.formResultId); if (model.editLocked) { if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, sf.formResultId, (int)AccessLogging.accessLogFunctions.REVIEW, "Assessment accessed for review."); } if (model.unlock == true) { formsRepo.LockFormResult(formResult.formResultId); } if (formResult.reviewStatus != (int)ReviewStatus.REVIEWED && formResult.reviewStatus != (int)ReviewStatus.APPROVED && formResult.reviewStatus != (int)ReviewStatus.PRE_QA) { def_FormResults preQAcopy = AssessmentCopy.CopyAssessment(formsRepo, formResult.formResultId); if (WebServiceActivity.IsWebServiceEnabled()) { WebServiceActivity.CallWebService(formsRepo, (int)WebServiceActivity.webServiceActivityFunctions.REVIEW, "formResultId=" + preQAcopy.formResultId.ToString()); } } ReviewStatus.ChangeStatus(formsRepo, formResult, ReviewStatus.REVIEWED, "Initiate review of assessment"); // get the sectionId of the first section of the first part based on the formId def_Forms frm = formsRepo.GetFormById(sf.formId); def_Parts prt = formsRepo.GetFormParts(frm)[0]; sf.partId = prt.partId; Session["part"] = prt.partId; def_Sections sct = formsRepo.GetSectionsInPart(prt)[0]; return(RedirectToAction("Template", "Results", new { sectionId = sct.sectionId.ToString(), partId = sf.partId.ToString() })); } } else if (category.ToLower().Equals("approve")) { // retrieve and set SessionForm params sf.formId = Convert.ToInt32(paramFormId); sf.formResultId = Convert.ToInt32(paramFormResultId); def_FormResults formResult = formsRepo.GetFormResultById(sf.formResultId); if (model.editLocked) { ReviewStatus.ChangeStatus(formsRepo, formResult, ReviewStatus.APPROVED, "Approve review of assessment"); if (WebServiceActivity.IsWebServiceEnabled()) { WebServiceActivity.CallWebService(formsRepo, (int)WebServiceActivity.webServiceActivityFunctions.APPROVE, "formResultId=" + formResult.formResultId.ToString()); } } } else if (category.ToLower().Equals("create")) { if (model.create == true) { string formId = String.IsNullOrEmpty(paramFormId) ? "1" : paramFormId; def_FormResults frmRes = FormResults.CreateNewFormResultFull(formId, SessionHelper.LoginStatus.EnterpriseID.ToString(), SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets[0].GroupID.ToString(), recId, SessionHelper.LoginStatus.UserID.ToString() ); string strFormResultId = String.Empty; try { int formRsltId = formsRepo.AddFormResult(frmRes); strFormResultId = formRsltId.ToString(); Debug.WriteLine("GoAction create FormResultId strFormResultId:" + strFormResultId); } catch (Exception excptn) { Debug.WriteLine("GoAction Defws.CreateNewFormResultFull formsRepo.AddFormResult exception:" + excptn.Message); Debug.WriteLine(" GoAction formId:" + formId + " entId: " + SessionHelper.LoginStatus.EnterpriseID.ToString() + " GroupId: " + SessionHelper.LoginStatus.appGroupPermissions[0].groupPermissionSets[0].GroupID.ToString() + " recId: " + recId.ToString() + " UserId: " + SessionHelper.LoginStatus.UserID.ToString() ); } if ((!String.IsNullOrEmpty(strFormResultId)) && !String.IsNullOrEmpty(recId)) { int intRecId; if (int.TryParse(recId, out intRecId)) { using (var context = DataContext.getSisDbContext()) { // Contact tempContact = new Contact(); Contact tempContact = (from c in context.Contacts where c.ContactID == intRecId select c).FirstOrDefault(); // Address tempAddress = new Address(); Address tempAddress = (from a in context.Addresses where (a.ContactID == tempContact.ContactID) && (a.AddressType == "R") select a).FirstOrDefault(); Dictionary <string, string> responsesByIdentifier = new Dictionary <string, string>(); responsesByIdentifier.Add("sis_cl_first_nm", tempContact.FirstName); responsesByIdentifier.Add("sis_cl_last_nm", tempContact.LastName); if (tempAddress != null) { responsesByIdentifier.Add("sis_cl_addr_line1", tempAddress.Address1); responsesByIdentifier.Add("sis_cl_city", tempAddress.City); responsesByIdentifier.Add("sis_cl_st", tempAddress.StateCode); responsesByIdentifier.Add("sis_cl_zip", tempAddress.Zip); } string msg = formsRepo.CreateNewResponseValues(strFormResultId, responsesByIdentifier); Debug.WriteLine("GoAction CreateNewResponseValues strFormResultId: " + strFormResultId + " msg: " + msg); } } // Retrieve and set SessionForm params sf.formId = 1; // Temporary sf.formResultId = Convert.ToInt32(strFormResultId); // Get the sectionId of the first section of the first part based on the formId def_Forms frm = formsRepo.GetFormById(sf.formId); def_Parts prt = formsRepo.GetFormParts(frm)[0]; sf.partId = prt.partId; Session["part"] = prt.partId; def_Sections sct = formsRepo.GetSectionsInPart(prt)[0]; return(RedirectToAction("Template", "Results", new { sectionId = sct.sectionId.ToString(), partId = sf.partId.ToString() })); } } } else if (category.ToLower().Equals("delete")) { if (model.delete == true) { formsRepo.FormResultDeleteLogically(Convert.ToInt32(paramFormResultId)); if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, Convert.ToInt32(paramFormResultId), (int)AccessLogging.accessLogFunctions.DELETE, "Delete assessment."); } if (ventureMode == false && WebServiceActivity.IsWebServiceEnabled()) { WebServiceActivity.CallWebService(formsRepo, (int)WebServiceActivity.webServiceActivityFunctions.DELETE, "formResultId=" + paramFormResultId); def_FormResults preQAcopy = ReviewStatus.GetLatestPreQACopy(formsRepo, Convert.ToInt32(paramFormResultId)); if (preQAcopy != null) { formsRepo.FormResultDeleteLogically(preQAcopy.formResultId); WebServiceActivity.CallWebService(formsRepo, (int)WebServiceActivity.webServiceActivityFunctions.DELETE, "formResultId=" + preQAcopy.formResultId.ToString()); } } } } else if (category.ToLower().Equals("lock")) { if (model.unlock == true) { formsRepo.LockFormResult(Convert.ToInt32(paramFormResultId)); } } else if (category.ToLower().Equals("unlock")) { if (model.unlock == true) { formsRepo.UnlockFormResult(Convert.ToInt32(paramFormResultId)); } } else if (category.ToLower().Equals("archive")) { if (model.archive == true) { formsRepo.ArchiveFormResult(Convert.ToInt32(paramFormResultId)); if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, Convert.ToInt32(paramFormResultId), (int)AccessLogging.accessLogFunctions.ARCHIVE, "Archive assessment."); } } } else if (category.ToLower().Equals("unarchive")) { if (model.archive == true) { formsRepo.UnarchiveFormResult(Convert.ToInt32(paramFormResultId)); if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, Convert.ToInt32(paramFormResultId), (int)AccessLogging.accessLogFunctions.UNARCHIVE, "Unarchive assessment."); } } } else if (category.ToLower().Equals("upload")) { def_FormResults fr = formsRepo.GetFormResultById(Convert.ToInt32(paramFormResultId)); if (fr.formStatus == (byte)FormResults_formStatus.COMPLETED) { SessionHelper.Write("uploadFormResultId", Convert.ToInt32(paramFormResultId)); return(RedirectToAction("UploadSingle", "DataSync")); } } else if (category.ToLower().Equals("undelete")) { if (model.undelete == true) { formsRepo.FormResultUndelete(Convert.ToInt32(paramFormResultId)); if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, Convert.ToInt32(paramFormResultId), (int)AccessLogging.accessLogFunctions.UNDELETE, "Undelete assessment."); } } } else if (category.ToLower().Equals("planning") && model.edit) { // retrieve and set SessionForm params sf.formId = Convert.ToInt32(paramFormId); sf.formResultId = Convert.ToInt32(paramFormResultId); def_FormResults formResult = formsRepo.GetFormResultById(sf.formResultId); if (!formResult.locked || (formResult.locked && model.editLocked)) { // get the sectionId of the first section of the first part based on the formId def_Forms frm = formsRepo.GetFormById(sf.formId); def_Parts prt = formsRepo.GetPartByFormAndIdentifier(frm, "Other"); sf.partId = prt.partId; Session["part"] = prt.partId; def_Sections sct = formsRepo.GetSectionsInPart(prt)[0]; if (ventureMode == false) { AccessLogging.InsertAccessLogRecord(formsRepo, sf.formResultId, (int)AccessLogging.accessLogFunctions.EDIT, "Initiate editing of interview planning."); } return(RedirectToAction("Template", "Results", new { sectionId = sct.sectionId.ToString(), partId = sf.partId.ToString() })); } } return(RedirectToAction("Index", "Search")); }
public FileContentResult GetBatchPdfReport() { //debug //Debug.WriteLine( "* * * GetBatchPdfReport start " + DateTime.Now.Ticks ); foreach (var v in Session.Keys) { Debug.WriteLine("Search GetBatchPdfReport Session Keys: " + v); } // Retrieve a list of formresults to export ExportModel exportModel = (ExportModel)Session["ExportModel"]; SearchModel search = (SearchModel)Session["SearchModel"]; if (exportModel == null) { exportModel = new ExportModel(); } if (exportModel.formResultIds == null) { if (search != null) { exportModel.formResultIds = search.vSearchResult.GroupBy(sr => sr.formResultId).Select(grp => (int?)grp.Key).ToList(); } else { exportModel.formResultIds = new List <int?>(); } } List <int?> formResultIds = exportModel.formResultIds; // Build a zip archive containing one PDF per assessment MemoryStream zipStream = new MemoryStream(); using (zipStream) { using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true)) { foreach (int frId in formResultIds) { def_FormResults fr = formsRepo.GetFormResultById(frId); //skip form results that are not complete if (fr.formStatus != (byte)FormResults_formStatus.COMPLETED) { continue; } //generate PDF report with default options based on the formResult's enterprise SisPdfReportOptions options = AJBoggs.Sis.Reports.SisReportOptions.BuildPdfReportOptions(fr.EnterpriseID); SisPdfRptsController sprc = new SisPdfRptsController(formsRepo); FileContentResult fcr = sprc.BottomBuildReport(frId, options); //add the new pdf to the result (zip file) var zipEntry = zip.CreateEntry(fcr.FileDownloadName); using (Stream entryStream = zipEntry.Open()) { entryStream.Write(fcr.FileContents, 0, fcr.FileContents.Length); } //debug //Debug.WriteLine("* * * GetBatchPdfReport finished formResult " + frId + " - " + DateTime.Now.Ticks); } } } return(File(zipStream.ToArray(), "multipart/x-zip", "reports.zip")); }
//called by all report-building methods public FileContentResult BottomBuildReport(int formResultId, SisPdfReportOptions options) { //construct a report object, containing instructions for building the pdf string logoPath = HostingEnvironment.MapPath("/Content/images/aaidd_logo_full.jpg"); string outpath = HostingEnvironment.MapPath("/Content/report_" + System.DateTime.Now.Ticks + ".pdf"); SisPdfReport report; def_FormResults fr = formsRepo.GetFormResultById(formResultId); string entLogoPath = String.Empty; try { // custom enterprise logo is located at /websiteroot/Enterprise/EnterpriseID/logo-left.png entLogoPath = Path.Combine(ConfigurationManager.AppSettings["EnterpriseDir"], fr.EnterpriseID.ToString()) + "\\logo-left.png"; } catch (Exception ex) { Debug.WriteLine("SisPdfRpts: BottomBuildReport: Unable to load custom logo for enterprise. Message: " + ex.Message); } if (System.IO.File.Exists(entLogoPath)) { logoPath = entLogoPath; } else { logoPath = HostingEnvironment.MapPath("/Content/images/aaidd_logo_full.jpg"); } try { // LK 3/26/2015 #12436 Added check on authorization for group to a central method (hasAccess) and used here if (!UAS_Business_Functions.hasAccess(fr)) { throw new Exception("You do not have access to this assessment record."); } //build report or reject, based on options and securityset if (options.type == SisPdfReportOptions.ReportType.Family) { if (!UAS_Business_Functions.hasPermission(PermissionConstants.FAMREP, "reportexp"))//String.IsNullOrEmpty(reportexpSet) || reportexpSet[0] != 'Y') { throw new Exception("You do not have permission to build a family-friendly report"); } report = new SisFamilyReport(formsRepo, formResultId, options, logoPath, outpath); } else if (options.type == SisPdfReportOptions.ReportType.Generic) { if (!UAS_Business_Functions.hasPermission(PermissionConstants.GENREP, "reportexp"))//String.IsNullOrEmpty(reportexpSet) || (reportexpSet[1] != 'Y') ) { throw new Exception("You do not have permission to build a generic report"); } report = new SisGenericReport(formsRepo, formResultId, options, logoPath, outpath); } else { if (!UAS_Business_Functions.hasPermission(PermissionConstants.EXPORT, "reportexp"))//String.IsNullOrEmpty(reportexpSet) || reportexpSet[2] != 'Y') { throw new Exception("You do not have permission to build a default report"); } report = new SisShortLongReport(formsRepo, formResultId, options, logoPath, outpath); } } catch (Exception xcptn) { string msg = "Build Report constructor failed. Exception: " + xcptn.Message; return(new FileContentResult(Encoding.ASCII.GetBytes(msg), "text/html")); } //build and save the pdf //try //{ report.BuildReport(); //} //catch (Exception xcptn) //{ // string msg = "BuildReport process failed. Exception: " + xcptn.Message; // return new FileContentResult(Encoding.ASCII.GetBytes(msg), "text/html"); //} FileContentResult result; try { Debug.WriteLine(" SisPdfRptsController outpath:" + outpath); report.outputToFile(); //build a descriptive filename string sDate = DateTime.Now.ToString("MM-dd-yyyy"); string lastName = getResponseStringOrEmpty(formResultId, "sis_cl_last_nm"); string firstName = getResponseStringOrEmpty(formResultId, "sis_cl_first_nm"); string filename = String.Format("{0}_{1}_{2}_{3}.pdf", lastName, firstName, formResultId, sDate); //build the result object containing the file contents result = File(System.IO.File.ReadAllBytes(outpath), "application/pdf", filename); //delete the original file System.IO.File.Delete(outpath); } catch (Exception xcptn) { string msg = "Build Report output failed. Exception: " + xcptn.Message; result = new FileContentResult(Encoding.ASCII.GetBytes(msg), "text/html"); } return(result); }
public ActionResult CreateAdapApplication() { def_Forms frm = formsRepo.GetFormByIdentifier("ADAP"); //string userId = Request["userId"]; int userId = 0; try { userId = Convert.ToInt32(Request["userId"]); } catch (Exception excptn) { Debug.WriteLine("Adap Controller CreateAdapApplication exception:" + excptn.Message); } int? intSO = formsRepo.GetStatusDetailByMasterIdentifier(1, "CANCELLED").sortOrder; def_FormResults prevRes = formsRepo.GetEntities <def_FormResults>(x => x.formId == frm.formId && x.subject == userId && x.formStatus != intSO) .OrderByDescending(x => x.dateUpdated) .FirstOrDefault(); //def_FormResults prevRes = frm.def_FormResults.Where(f => f.subject == userId && intSO != null && f.formStatus != intSO).OrderByDescending(f => f.dateUpdated).FirstOrDefault(); if ((prevRes == null) || (prevRes.formStatus == formsRepo.GetStatusDetailByMasterIdentifier(1, "APPROVED").sortOrder)) { AuthenticationClient webclient = new AuthenticationClient(); UserDisplay ud = webclient.GetUserDisplay(userId); Dictionary <string, string> ItemsToPopulateFromUAS = new Dictionary <string, string>(); ItemsToPopulateFromUAS.Add( "ADAP_D1_FirstName_item", String.IsNullOrEmpty(ud.FirstName) ? String.Empty : ud.FirstName); ItemsToPopulateFromUAS.Add( "ADAP_D1_LastName_item", String.IsNullOrEmpty(ud.LastName) ? String.Empty : ud.LastName); ItemsToPopulateFromUAS.Add( "ADAP_D1_MiddleIntl_item", String.IsNullOrEmpty(ud.MiddleName) ? String.Empty : ud.MiddleName.Substring(0, 1)); ItemsToPopulateFromUAS.Add( "ADAP_D2_DOB_item", (ud.DOB == null) ? String.Empty : Convert.ToDateTime(ud.DOB).ToString("MM/dd/yyyy")); ItemsToPopulateFromUAS.Add( "ADAP_C1_Address_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].Address1 : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C1_MayContactYN_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ((ud.Addresses[0].MayContactAddress) ? "1" : "0") : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C1_City_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].City : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C1_State_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].State : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C1_Zip_item", (ud.Addresses != null && ud.Addresses.Count() > 0) ? ud.Addresses[0].ZIP : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C2_Address_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].Address1 : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C2_MayContactYN_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ((ud.Addresses[1].MayContactAddress) ? "1" : "0") : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C2_City_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].City : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C2_State_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].State : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C2_Zip_item", (ud.Addresses != null && ud.Addresses.Count() > 1) ? ud.Addresses[1].ZIP : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C3_Phone1_Num_item", (ud.Phones != null && ud.Phones.Count() > 0) ? ud.Phones[0].Phone : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C3_Phone1_MayMsgYN_item", (ud.Phones != null && ud.Phones.Count() > 0) ? ((ud.Phones[0].MayContactPhone) ? "1" : "0") : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C3_Phone2_Num_item", (ud.Phones != null && ud.Phones.Count() > 1) ? ud.Phones[1].Phone : String.Empty); ItemsToPopulateFromUAS.Add( "ADAP_C3_Phone2_MayMsgYN_item", (ud.Phones != null && ud.Phones.Count() > 1) ? ((ud.Phones[1].MayContactPhone) ? "1" : "0") : String.Empty); // * * * OT 1-20-16 updated this list based on Docs/ADAP/ADAP_item_list.xslx (revision 80734) string[] ItemIdentifiersToPopulateFromPrevApplication = new string[] { #region long list of item identifiers "ADAP_D1_LastName_item", "ADAP_D1_FirstName_item", "ADAP_D1_MiddleIntl_item", "ADAP_D1_AltName_item", "ADAP_D2_DOB_item", "ADAP_D3_White_item", "ADAP_D3_Black_item", "ADAP_D3_Asian_item", "ADAP_D3_Native_item", "ADAP_D3_Indian_item", "ADAP_D4_EthnicDrop_item", "ADAP_D4_Mexican_item", "ADAP_D4_Puerto_item", "ADAP_D4_Cuban_item", "ADAP_D4_Other_item", "ADAP_D5_Indian_item", "ADAP_D5_Filipino_item", "ADAP_D5_Korean_item", "ADAP_D5_Other_item", "ADAP_D5_Chinese_item", "ADAP_D5_Japanese_item", "ADAP_D5_Vietnamese_item", "ADAP_D5_NA_item", "ADAP_D6_Native_item", "ADAP_D6_Guam_item", "ADAP_D6_Samoan_item", "ADAP_D6_Other_item", "ADAP_D6_NA_item", "ADAP_D7_LangDrop_item", "ADAP_D7_LangOther_item", "ADAP_D8_CurrGenderDrop_item", "ADAP_D8_BirthGenderDrop_item", "ADAP_D9_Ramsell_item", "ADAP_D10_SSN_item", "ADAP_C1_Address_item", "ADAP_C1_City_item", "ADAP_C1_State_item", "ADAP_C1_Zip_item", "ADAP_C1_County_item", "ADAP_C1_MayContactYN_item", "ADAP_C2_SameAsMailing_item", "ADAP_C2_Address_item", "ADAP_C2_City_item", "ADAP_C2_State_item", "ADAP_C2_Zip_item", "ADAP_C2_County_item", "ADAP_C2_MayContactYN_item", "ADAP_C3_Phone1_Num_item", "ADAP_C3_Phone1_Type_item", "ADAP_C3_Phone1_MayMsgYN_item", "ADAP_C3_Phone2_Num_item", "ADAP_C3_Phone2_Type_item", "ADAP_C3_Phone2_MayMsgYN_item", "ADAP_C4_MayCallYN_item", "ADAP_C4_Name_item", "ADAP_C4_Phone_item", "ADAP_C4_KnowHivYN_item", "ADAP_C5_HasCaseMngrYN_item", "ADAP_C5_Mngr1_Name_item", "ADAP_C5_Mngr1_Clinic_item", "ADAP_C5_Mngr2_Name_item", "ADAP_C5_Mngr2_Clinic_item", "ADAP_C5_CanReferYN_item", "ADAP_M1_Month_item", "ADAP_M1_Year_item", "ADAP_M1_DiagnosisLoc_item", "ADAP_M2_ToldAIDS_item", "ADAP_M3_ToldHepC_item", "ADAP_M4_Clinic_item", "ADAP_I1_Med_Yes_item", "ADAP_I1_Med_Denied_item", "ADAP_I1_Med_No_item", "ADAP_I1_Med_Waiting_item", "ADAP_I1_Med_DontKnow_item", "ADAP_I1_DeniedReason_item", "ADAP_I1_NotAppliedReason_item", "ADAP_I2_AffCareOpt_item", "ADAP_I2_AffCareOther_item", "ADAP_I3_MedicareYN_item", "ADAP_I3_MedNumber_item", "ADAP_I3_PartAYN_item", "ADAP_I3_PartBYN_item", "ADAP_I3_PartADate_item", "ADAP_I3_PartBDate_item", "ADAP_H1_StatusDrop_item", "ADAP_H2_RelnDrop_item", "ADAP_H2_RelnOther_item", "ADAP_H3_FileTaxYN_item", "ADAP_H3_TaxStatusOpt_item", "ADAP_H3_TaxDependants_item", "ADAP_H3_TaxNotFileOpt_item", "ADAP_H3_TaxNotFileOther_item", "ADAP_H3_Relatives_item", "ADAP_H4_ChildrenIn_item", "ADAP_H4_ChildrenOut_item", "ADAP_F1_EmployOpt_item", "ADAP_F1_EmployOther_item", "ADAP_F1_EmployerInsOpt_item", "ADAP_F1_EmployNotEnrolled_item", "ADAP_F2_EmployLast90YN_item", "ADAP_F3_A_Recipient_item", "ADAP_F3_A_IncomeTypeDrop_item", "ADAP_F3_A_Employer_item", "ADAP_F3_A_EmployStart_item", "ADAP_F3_A_TempYN_item", "ADAP_F3_A_IncomeTypeOther_item", "ADAP_F3_A_IncomeAmt_item", "ADAP_F3_A_EmployerForm_item", "ADAP_F3_B_Recipient_item", "ADAP_F3_B_IncomeTypeDrop_item", "ADAP_F3_B_Employer_item", "ADAP_F3_B_EmployStart_item", "ADAP_F3_B_TempYN_item", "ADAP_F3_B_IncomeTypeOther_item", "ADAP_F3_B_IncomeAmt_item", "ADAP_F3_B_EmployerForm_item", "ADAP_F3_C_Recipient_item", "ADAP_F3_C_IncomeTypeDrop_item", "ADAP_F3_C_Employer_item", "ADAP_F3_C_EmployStart_item", "ADAP_F3_C_TempYN_item", "ADAP_F3_C_IncomeTypeOther_item", "ADAP_F3_C_IncomeAmt_item", "ADAP_F3_C_EmployerForm_item", "ADAP_F3_D_Recipient_item", "ADAP_F3_D_IncomeTypeDrop_item", "ADAP_F3_D_Employer_item", "ADAP_F3_D_EmployStart_item", "ADAP_F3_D_TempYN_item", "ADAP_F3_D_IncomeTypeOther_item", "ADAP_F3_D_IncomeAmt_item", "ADAP_F3_D_EmployerForm_item", "ADAP_cert_NoSharing_item", "ADAP_cert_Reminders_item" #endregion }; Applications appl = new Applications(formsRepo); def_FormResults frmRes = appl.CreateFormResultPopulatedFromUAS(SessionHelper.LoginStatus.EnterpriseID, SessionHelper.LoginStatus.GroupID, userId, frm.formId, ItemsToPopulateFromUAS); appl.PopulateItemsFromPrevApplication(frmRes, ItemIdentifiersToPopulateFromPrevApplication); frmRes.statusChangeDate = DateTime.Now; // Save the FormResult, ItemResults, and ResponseVariables int newFormResultId = 0; try { newFormResultId = formsRepo.AddFormResult(frmRes); } catch (Exception ex) { Debug.WriteLine("AddFormResult exception:" + ex.Message); } Debug.WriteLine("AddFormResult newFormResultId:" + newFormResultId.ToString()); // query the ramsell system and update the formResult responses based on Ramsell response def_ResponseVariables rvMemberId = formsRepo.GetResponseVariablesByFormResultIdentifier(newFormResultId, "ADAP_D9_Ramsell"); if (rvMemberId != null && !String.IsNullOrWhiteSpace(rvMemberId.rspValue)) { string memberId = rvMemberId.rspValue; string usrId = UAS.Business.UAS_Business_Functions.GetEntAppConfigAdap("USR"); string password = UAS.Business.UAS_Business_Functions.GetEntAppConfigAdap("PWD"); Debug.WriteLine("Ramsell UseriD / Password: "******" / " + password); string token = Ramsell.GetOauthToken(usrId, password); new RamsellImport(formsRepo, frmRes.formResultId).ImportApplication(token, memberId); } //AJBoggs.Adap.Services.Api.Ramsell.PopulateItemsFromRamsellImport(formsRepo, frmRes); if (SessionHelper.SessionForm == null) { SessionHelper.SessionForm = new SessionForm(); } SessionForm sf = SessionHelper.SessionForm; sf.formId = frm.formId; sf.formIdentifier = frm.identifier; sf.sectionId = formsRepo.GetSectionByIdentifier("ADAP_demographic").sectionId; sf.partId = formsRepo.GetPartByFormAndIdentifier(frm, "ADAP").partId; // *** RRB - should be deprecated - use SessionForm // *** BR - line 359 of the ResultsController calls this session variable, so it must be set to prevent an exception. // Other parts of the application may still use that variable, so changing it in the ResultsController may break something else. Session["part"] = sf.partId; // Should have the partId also - may not be required. sf.formResultId = newFormResultId; return(RedirectToAction("Template", "Results", new { sectionId = sf.sectionId.ToString() })); } else { return(RedirectToAction("AdapPortal", "COADAP", new { userId = userId, error = "Not Approved" })); } }
private void Upload_ProcessSingleSectionNode(XmlNode sectionNode, int sectionNum, string sectionPartLetter, def_FormResults formResult, bool oldFormat) { foreach (XmlNode sectionChildNode in sectionNode) { switch (sectionChildNode.Name) { case "Question": Upload_ProcessQuestionNode(sectionChildNode, sectionNum, sectionPartLetter, formResult, oldFormat); break; } } }
public MoveModel(int frID, IFormsRepository fr) { LoginIDs = new List <SelectListItem>(); formResultId = frID; formsRepo = fr; def_FormResults formResult = formsRepo.GetFormResultById(formResultId); def_ResponseVariables rvFirst = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, "sis_cl_first_nm"); if (rvFirst != null) { firstName = rvFirst.rspValue; } def_ResponseVariables rvLast = formsRepo.GetResponseVariablesByFormResultIdentifier(formResultId, "sis_cl_last_nm"); if (rvLast != null) { lastName = rvLast.rspValue; } recipientID = formResult.subject; using (var context = DataContext.getUasDbContext()) { if (formResult.EnterpriseID != null) { enterprise = context.uas_Enterprise.Where(e => e.EnterpriseID == formResult.EnterpriseID).Select(e => e.EnterpriseName).FirstOrDefault(); selectedEnterprise = (int)formResult.EnterpriseID; } if (formResult.GroupID != null) { group = context.uas_Group.Where(g => g.GroupID == formResult.GroupID).Select(g => g.GroupName).FirstOrDefault(); selectedGroup = (int)formResult.GroupID; } if (formResult.assigned != null) { uas_User assignedUser = context.uas_User.Where(u => u.UserID == formResult.assigned).Select(u => u).FirstOrDefault(); selectedUser = (int)formResult.assigned; if (assignedUser != null) { assigned = assignedUser.UserName; //if (assignedUser.StatusFlag != "A") //{ // assigned += " (inactive)"; //} } } LoginIDs.Add(new SelectListItem { Value = "", Text = "" }); if (SessionHelper.LoginStatus.EnterpriseID == 0) // User has site wide (all enterprise) access { Enterprises = new List <SelectListItem>(); Groups = new List <SelectListItem>(); List <uas_Enterprise> enterprises = context.uas_Enterprise.Where(e => e.StatusFlag == "A").Select(e => e).ToList(); foreach (uas_Enterprise ent in enterprises) { Enterprises.Add(new SelectListItem { Value = ent.EnterpriseID.ToString(), Text = ent.EnterpriseName }); } List <uas_Group> groups = context.uas_Group.Where(g => g.StatusFlag == "A" && g.EnterpriseID == selectedEnterprise).Select(g => g).ToList(); Groups.Add(new SelectListItem { Value = "", Text = "" }); foreach (uas_Group grp in groups) { Groups.Add(new SelectListItem { Value = grp.GroupID.ToString(), Text = grp.GroupName }); } List <uas_User> users = null; if (selectedGroup > 0) { List <int> userIdsForUserGroup = context.uas_GroupUserAppPermissions.Where(g => selectedGroup == g.uas_Group.GroupID && g.StatusFlag == "A").Select(g => g.UserID).ToList(); users = context.uas_User.Where(u => u.EnterpriseID == selectedEnterprise && userIdsForUserGroup.Contains(u.UserID) && u.StatusFlag == "A").Select(u => u).ToList(); } else { users = context.uas_User.Where(u => u.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID).Select(u => u).ToList(); } foreach (uas_User user in users) { LoginIDs.Add(new SelectListItem { Value = user.UserID.ToString(), Text = user.UserName }); } } else if (SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups.Contains(0)) // User has enterprise wide access (all groups/users in enterprise) { Groups = new List <SelectListItem>(); List <uas_User> users = context.uas_User.Where(u => u.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && u.StatusFlag == "A").Select(u => u).ToList(); foreach (uas_User user in users) { LoginIDs.Add(new SelectListItem { Value = user.UserID.ToString(), Text = user.UserName }); } List <uas_Group> groups = context.uas_Group.Where(g => g.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && g.StatusFlag == "A").Select(g => g).ToList(); Groups.Add(new SelectListItem { Value = "", Text = "" }); foreach (uas_Group grp in groups) { Groups.Add(new SelectListItem { Value = grp.GroupID.ToString(), Text = grp.GroupName }); } } else // Regular user. No selection for enterprise or group. { var authorizedGroups = SessionHelper.LoginStatus.appGroupPermissions[0].authorizedGroups; List <int> userIdsForUserGroup = context.uas_GroupUserAppPermissions.Where(g => authorizedGroups.Contains(g.uas_Group.GroupID) && g.StatusFlag == "A").Select(g => g.UserID).ToList(); List <uas_User> users = context.uas_User.Where(u => u.EnterpriseID == SessionHelper.LoginStatus.EnterpriseID && userIdsForUserGroup.Contains(u.UserID) && u.StatusFlag == "A").Select(u => u).ToList(); foreach (uas_User user in users) { LoginIDs.Add(new SelectListItem { Value = user.UserID.ToString(), Text = user.UserName }); } } } }
//private static void AddHiddenField(IFormsRepository formsRepo, def_FormResults formResult, string fieldName, string value) //{ // int itemId = formsRepo.GetItemByIdentifier(SIS_HIDDEN).itemId; // def_ItemResults itemResult = formsRepo.GetItemResultByFormResItem(formResult.formResultId, itemId); // def_ResponseVariables relatedFormResultRV = null; // try // { // relatedFormResultRV = formsRepo.GetResponseVariablesByFormResultIdentifier(formResult.formResultId, fieldName); // } // catch (Exception ex) // { // Console.WriteLine(ex.Message); // } // def_ItemVariables itemVariableRelated = formsRepo.GetItemVariableByIdentifier(fieldName); // if (itemVariableRelated != null) // { // if (relatedFormResultRV != null) // { // relatedFormResultRV.rspValue = value; // formsRepo.ConvertValueToNativeType(itemVariableRelated, relatedFormResultRV); // } // else // { // relatedFormResultRV = new def_ResponseVariables(); // relatedFormResultRV.itemResultId = itemResult.itemResultId; // relatedFormResultRV.itemVariableId = itemVariableRelated.itemVariableId; // relatedFormResultRV.rspValue = value; // formsRepo.ConvertValueToNativeType(itemVariableRelated, relatedFormResultRV); // formsRepo.AddResponseVariableNoSave(relatedFormResultRV); // } // } // formsRepo.Save(); //} private static void CopyAssessmentData(IFormsRepository formsRepo, int oldFormResultId, def_FormResults copyFormResult) { try { IUasSql uasSql = new UasSql(); using (DbConnection connection = new SqlConnection(uasSql.GetConnectionString())) { connection.Open(); using (DbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT IR.itemId, RV.itemVariableId, RV.rspValue from def_ItemResults IR JOIN def_FormResults FR on FR.formResultId = IR.formResultId JOIN def_ResponseVariables RV on RV.itemResultId = IR.itemResultId WHERE FR.formResultId = " + oldFormResultId + " ORDER BY itemId"; command.CommandType = CommandType.Text; DataTable dt = new DataTable(); dt.Load(command.ExecuteReader()); if (dt != null) { SaveAssessmentFromDataTable(formsRepo, copyFormResult, dt); } } } } catch (Exception ex) { Debug.WriteLine("* * * CreateFormResultJSON exception: " + ex.Message); } }
private void Upload_ProcessQuestionNode(XmlNode questionNode, int sectionNum, string sectionPartLetter, def_FormResults formResult, bool oldFormat) { int questionNum = getIntAttribute(questionNode, "num"); if (oldFormat) { questionNum = mapOldQuestionNumToNewSystem(questionNum, sectionNum, sectionPartLetter); } foreach (XmlNode questionChildNode in questionNode) { string suffix; switch (questionChildNode.Name) { case "Frequency": suffix = "Fqy"; break; case "DailySupport": suffix = "DST"; break; case "TypeOfSupport": suffix = "TOS"; break; case "ImportantTo": suffix = "ImportantTo"; break; case "ImportantFor": suffix = "ImportantFor"; break; case "Notes": suffix = "Notes"; break; case "SupportNeeds": suffix = sectionPartLetter.Equals("A") ? "ExMedSupport" : "ExBehSupport"; break; case "Other": suffix = "Other"; break; default: Debug.WriteLine("Unrecognized question child node name \"" + questionChildNode.Name + "\""); suffix = questionChildNode.Name; break; } string identifier; if (suffix.Equals("Other")) { identifier = sectionPartLetter.Equals("A") ? "S1aPageOther" : "S1bPageOther"; } else { identifier = "Q" + sectionNum + sectionPartLetter + questionNum + "_" + suffix; } Upload_SaveResponseVariable(identifier, questionChildNode.InnerText, formResult); } }
/// <summary> /// Gets data from the def_FormResults record for a form result /// </summary> /// <param name="formResult">The form result to get data from</param> /// <param name="form">The form result's form</param> /// <returns>ValuePairs containing identifier = label for a form result entry, value = the form result entry (string)</returns> public static List <ValuePair> GetFormResultValues(def_FormResults formResult, def_Forms form) { List <ValuePair> values = new List <ValuePair>(); //number ValuePair valuePair = new ValuePair(FormResultExportTagName.recipientId.ToString(), formResult.subject.ToString()); values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.formResultId.ToString(), formResult.formResultId.ToString()); values.Add(valuePair); //^ SisId in csv second row //text valuePair = new ValuePair(FormResultExportTagName.identifier.ToString(), form.identifier); values.Add(valuePair); //add formId (number) valuePair = new ValuePair(FormResultExportTagName.formId.ToString(), form.formId.ToString()); values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.group.ToString(), formResult.GroupID.ToString()); values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.enterprise.ToString(), formResult.EnterpriseID.ToString()); values.Add(valuePair); ////number //valuePair = new ValuePair(interviewerId, formResult.interviewer.ToString()); //values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.assigned.ToString(), formResult.assigned.ToString()); values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.statusId.ToString(), formResult.formStatus.ToString()); values.Add(valuePair); //text valuePair = new ValuePair(FormResultExportTagName.dateUpdated.ToString(), formResult.dateUpdated.ToString()); values.Add(valuePair); //text valuePair = new ValuePair(FormResultExportTagName.statusChangeDate.ToString(), formResult.statusChangeDate.ToString()); values.Add(valuePair); valuePair = new ValuePair(FormResultExportTagName.deleted.ToString(), formResult.deleted.ToString()); values.Add(valuePair); valuePair = new ValuePair(FormResultExportTagName.locked.ToString(), formResult.locked.ToString()); values.Add(valuePair); valuePair = new ValuePair(FormResultExportTagName.archived.ToString(), formResult.archived.ToString()); values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.reviewStatus.ToString(), formResult.reviewStatus.ToString()); values.Add(valuePair); //number valuePair = new ValuePair(FormResultExportTagName.lastModifiedByUserId.ToString(), formResult.LastModifiedByUserId.ToString()); values.Add(valuePair); //pull info that comes from other def tables using (formsEntities def = DataContext.GetDbContext()) { try { int statusMasterId = def.def_StatusMaster.Where(sm => sm.formId == 1 && sm.ApplicationId == 1).Select(sm => sm.statusMasterId).First(); int statusDetailId = def.def_StatusDetail.Where(sd => sd.statusMasterId == statusMasterId && sd.sortOrder == formResult.reviewStatus).Select(sd => sd.statusDetailId).First(); string reviewStatusText = def.def_StatusText.Where(st => st.statusDetailId == statusDetailId).Select(st => st.displayText).First(); valuePair = new ValuePair(FormResultExportTagName.reviewStatusText.ToString(), reviewStatusText); values.Add(valuePair); } catch (Exception e) { Debug.WriteLine(e); } try { valuePair = new ValuePair(FormResultExportTagName.statusText.ToString(), ((WebService.WSConstants.FR_formStatus)(formResult.formStatus)).ToString()); values.Add(valuePair); } catch (Exception e) { Debug.WriteLine(e); } } //pull info that comes from uas tables using (UASEntities uas = DataContext.getUasDbContext()) { try { valuePair = new ValuePair(FormResultExportTagName.groupName.ToString(), uas.uas_Group .Where(g => g.GroupID == formResult.GroupID) .Select(g => g.GroupName).First()); values.Add(valuePair); } catch (Exception e) { Debug.WriteLine(e); } try { valuePair = new ValuePair(FormResultExportTagName.assignedLoginId.ToString(), uas.uas_User .Where(u => u.UserID == formResult.assigned) .Select(u => u.LoginID).First()); values.Add(valuePair); } catch (Exception e) { Debug.WriteLine(e); } try { valuePair = new ValuePair(FormResultExportTagName.lastModifiedByLoginId.ToString(), uas.uas_User .Where(u => u.UserID == formResult.LastModifiedByUserId) .Select(u => u.LoginID).First()); values.Add(valuePair); } catch (Exception e) { Debug.WriteLine(e); } try { valuePair = new ValuePair(FormResultExportTagName.enterpriseName.ToString(), uas.uas_Enterprise .Where(e => e.EnterpriseID == formResult.EnterpriseID) .Select(e => e.EnterpriseName).First()); values.Add(valuePair); } catch (Exception e) { Debug.WriteLine(e); } } return(values); }
public ActionResult Index() { Session["userId"] = "0"; Debug.WriteLine("* * * ExportController:Index method * * *"); // Initialize the session variables SessionForm sf = (SessionForm)Session["sessionForm"]; if (sf == null) { sf = new SessionForm() { formId = 0, partId = 0, sectionId = 0, formResultId = 0 }; Session["sessionForm"] = sf; } // Display the formResults (Assessments) Assmnts.Models.FormResults frmRsltsMdl = new Assmnts.Models.FormResults(); frmRsltsMdl.formResults = new List <def_FormResults>(); foreach (def_Forms frm in formsRepo.GetAllForms()) { frmRsltsMdl.formResults.AddRange(formsRepo.GetFormResultsByFormId(frm.formId)); } //frmRsltsMdl.formResults = formsRepo.GetAllFormResults(); bool noFormResults = false; if (frmRsltsMdl.formResults.Count() == 0) { Debug.WriteLine("* * * Index FormResults Count was 0. "); noFormResults = true; def_FormResults frmRslts = new def_FormResults() { formResultId = 0, formId = 0, dateUpdated = System.DateTime.Now }; frmRsltsMdl.formResults.Add(frmRslts); } else { Debug.WriteLine("* * * Index FormResults count: " + frmRsltsMdl.formResults.Count().ToString()); } frmRsltsMdl.formTitles = new List <String>(); if (noFormResults) { frmRsltsMdl.formTitles.Add("There are no Assessments in the system."); } else { foreach (def_FormResults frmRslt in frmRsltsMdl.formResults) { def_Forms frm = formsRepo.GetFormById(frmRslt.formId); if (frm != null) { frmRsltsMdl.formTitles.Add(frm.title); } } } return(View("formResults", frmRsltsMdl)); }