/// <summary> /// Handle HTTPPOST request coming in from the client after successful Authentication /// </summary> /// <param name="request"></param> /// <returns>HTTPRespose code with succee/failure</returns> public HttpResponseMessage PostSurveyAnswer(HttpRequestMessage request) { Dictionary <string, string> keyvalupair = new Dictionary <string, string>(); var value = request.Content.ReadAsStringAsync().Result; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; try { keyvalupair = JsonConvert.DeserializeObject <Dictionary <string, string> >(value, settings); } catch (Exception ex) { var responseexception = Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, ex.Message.ToString());//415 Unsupported media type The endpoint does not support the format of the request body. return(responseexception); } string responseId; SurveyResponseApiModel surveyanswerModel = new SurveyResponseApiModel(); surveyanswerModel.SurveyId = _isurveyAnswerRepository.SurveyId; surveyanswerModel.OrgKey = _isurveyAnswerRepository.OrgKey; surveyanswerModel.PublisherKey = _isurveyAnswerRepository.PublisherKey; surveyanswerModel.SurveyQuestionAnswerListField = keyvalupair; var item = keyvalupair.Where(x => x.Key.ToLower() == "responseid" || x.Key.ToLower() == "id").FirstOrDefault(); // if (keyvalupair.TryGetValue("ResponseId", out ResponseId)) if (item.Value != null) { responseId = item.Value; surveyanswerModel.SurveyQuestionAnswerListField = keyvalupair; var Result = _isurveyAnswerRepository.SetSurveyAnswer(surveyanswerModel); if (Result.SurveyResponseID != null) { var response = Request.CreateResponse <PreFilledAnswerResponse>(System.Net.HttpStatusCode.Created, Result);//201 Created Success with response body. string uri = Url.Link("DefaultApi", new { id = Result.SurveyResponseID }); response.Headers.Location = new Uri(uri); return(response); } else { var response = Request.CreateResponse(HttpStatusCode.Forbidden, "Response not generated");//The requested operation is not permitted for the user. This error can also be caused by ACL failures, or business rule or data policy constraints. return(response); } } else { var response = Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, "Response not generated");//415 Unsupported media type The endpoint does not support the format of the request body. return(response); } }
/// <summary> /// Inserts SurveyResponse /// </summary> /// <param name="SurveyResponseApiModel"></param> /// <returns>response </returns> public PreFilledAnswerResponse SetSurveyAnswer(SurveyResponseApiModel request) { PreFilledAnswerResponse response; SurveyControlsResponse SurveyControlsResponse = new SurveyControlsResponse(); SurveyControlsRequest surveyControlsRequest = new SurveyControlsRequest(); surveyControlsRequest.SurveyId = request.SurveyId.ToString(); try { Interfaces.DataInterfaces.ISurveyResponseDao SurveyResponseDao = new EntitySurveyResponseDao(); Epi.Web.Interfaces.DataInterfaces.ISurveyInfoDao ISurveyInfoDao = new EntitySurveyInfoDao(); BLL.SurveyResponse Implementation = new BLL.SurveyResponse(SurveyResponseDao, ISurveyInfoDao); PreFilledAnswerRequest prefilledanswerRequest = new PreFilledAnswerRequest(); Dictionary <string, string> Values = new Dictionary <string, string>(); prefilledanswerRequest.AnswerInfo.UserPublishKey = request.PublisherKey; prefilledanswerRequest.AnswerInfo.OrganizationKey = request.OrgKey; prefilledanswerRequest.AnswerInfo.SurveyId = request.SurveyId; prefilledanswerRequest.AnswerInfo.UserPublishKey = request.PublisherKey; List <SurveyInfoBO> SurveyBOList = GetSurveyInfo(prefilledanswerRequest); GetRootFormId(prefilledanswerRequest); prefilledanswerRequest.AnswerInfo.SurveyId = request.SurveyId; SurveyControlsResponse = GetSurveyControlsList(surveyControlsRequest); Dictionary <string, string> FilteredAnswerList = new Dictionary <string, string>(); var radiolist = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "GroupBoxRadioList"); FilteredAnswerList = ProcessModforRadioControls(radiolist, request.SurveyQuestionAnswerListField); var checkboxLsit = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "CheckBox"); FilteredAnswerList = ProcessValforCheckBoxControls(checkboxLsit, FilteredAnswerList); var yesNoList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "YesNo"); FilteredAnswerList = ProcessValforYesNoControls(yesNoList, FilteredAnswerList); var legalvalList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "LegalValues"); FilteredAnswerList = ProcessValforLegalControls(legalvalList, FilteredAnswerList); foreach (KeyValuePair <string, string> entry in FilteredAnswerList) { Values.Add(entry.Key, entry.Value); } prefilledanswerRequest.AnswerInfo.SurveyQuestionAnswerList = Values; response = Implementation.SetSurveyAnswer(prefilledanswerRequest); return(response); } catch (Exception ex) { PassCodeDTO DTOList = new PassCodeDTO(); response = new PreFilledAnswerResponse(DTOList); if (response.ErrorMessageList != null) { response.ErrorMessageList.Add("Failed", "Failed to insert Response"); } response.Status = ((BLL.SurveyResponse.Message) 1).ToString(); return(response); } }
/// <summary> /// Handle HTTPDELETE request coming in from the client after successful Authentication /// </summary> /// <param name="request"></param> /// <returns>HTTPRespose code with succee/failure</returns> public HttpResponseMessage Delete(HttpRequestMessage request) { Dictionary <string, string> keyvalupair = new Dictionary <string, string>(); var value = request.Content.ReadAsStringAsync().Result; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; try { keyvalupair = JsonConvert.DeserializeObject <Dictionary <string, string> >(value, settings); } catch (Exception ex) { var response = Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, ex.Message.ToString());//415 Unsupported media type The endpoint does not support the format of the request body. return(response); } string responseId; SurveyResponseApiModel surveyanswerModel = new SurveyResponseApiModel(); surveyanswerModel.SurveyId = _isurveyAnswerRepository.SurveyId; surveyanswerModel.OrgKey = _isurveyAnswerRepository.OrgKey; surveyanswerModel.PublisherKey = _isurveyAnswerRepository.PublisherKey; var item = keyvalupair.Where(x => x.Key.ToLower() == "responseid" || x.Key.ToLower() == "id").FirstOrDefault(); // if (keyvalupair.TryGetValue("ResponseId", out ResponseId)) if (item.Value != null) { responseId = item.Value; try { _isurveyAnswerRepository.Remove(responseId); } catch (Exception ex) { var exresponse = Request.CreateResponse(HttpStatusCode.Forbidden, "Response does not exist");//The request has not succeeded. The information returned with the response is dependent on the method used in the request. return(exresponse); } var response = Request.CreateResponse(HttpStatusCode.OK, "Response Deleted.");//The request has succeeded. The information returned with the response is dependent on the method used in the request. return(response); } else { var response = Request.CreateResponse(HttpStatusCode.UnsupportedMediaType, "Response not generated");//415 Unsupported media type The endpoint does not support the format of the request body. return(response); } }
/// <summary> /// Updates SurveyResponse /// </summary> /// <param name="SurveyResponseApiModel",name="ResponseId"></param> /// <returns>response </returns> public PreFilledAnswerResponse Update(SurveyResponseApiModel request, string ResponseId) { PreFilledAnswerResponse response; SurveyControlsResponse SurveyControlsResponse = new SurveyControlsResponse(); SurveyControlsRequest surveyControlsRequest = new SurveyControlsRequest(); surveyControlsRequest.SurveyId = request.SurveyId.ToString(); try { Interfaces.DataInterfaces.ISurveyResponseDao SurveyResponseDao = new EntitySurveyResponseDao(); Interfaces.DataInterfaces.ISurveyInfoDao ISurveyInfoDao = new EntitySurveyInfoDao(); BLL.SurveyResponse Implementation = new BLL.SurveyResponse(SurveyResponseDao, ISurveyInfoDao); PreFilledAnswerRequest prefilledanswerRequest = new PreFilledAnswerRequest(); Dictionary <string, string> Values = new Dictionary <string, string>(); prefilledanswerRequest.AnswerInfo.UserPublishKey = request.PublisherKey; prefilledanswerRequest.AnswerInfo.OrganizationKey = request.OrgKey; prefilledanswerRequest.AnswerInfo.SurveyId = request.SurveyId; prefilledanswerRequest.AnswerInfo.UserPublishKey = request.PublisherKey; List <SurveyInfoBO> SurveyBOList = GetSurveyInfo(prefilledanswerRequest); GetRootFormId(prefilledanswerRequest); prefilledanswerRequest.AnswerInfo.SurveyId = request.SurveyId; SurveyControlsResponse = GetSurveyControlsList(surveyControlsRequest); Dictionary <string, string> FilteredAnswerList = new Dictionary <string, string>(); var radiolist = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "GroupBoxRadioList"); FilteredAnswerList = ProcessModforRadioControls(radiolist, request.SurveyQuestionAnswerListField); var checkboxLsit = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "CheckBox"); FilteredAnswerList = ProcessValforCheckBoxControls(checkboxLsit, FilteredAnswerList); var yesNoList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "YesNo"); FilteredAnswerList = ProcessValforYesNoControls(yesNoList, FilteredAnswerList); var legalvalList = SurveyControlsResponse.SurveyControlList.Where(x => x.ControlType == "LegalValues"); FilteredAnswerList = ProcessValforLegalControls(legalvalList, FilteredAnswerList); var updatedtime = FilteredAnswerList.Where(x => x.Key.ToLower() == "_updatestamp").FirstOrDefault(); var Responsekey = FilteredAnswerList.Where(x => x.Key.ToLower() == "responseid" || x.Key.ToLower() == "id").FirstOrDefault().Key; var fkey = FilteredAnswerList.Where(x => x.Key.ToLower() == "fkey").FirstOrDefault(); foreach (KeyValuePair <string, string> entry in FilteredAnswerList) { Values.Add(entry.Key, entry.Value); } try { var survey = Implementation.GetSurveyResponseById(new List <string> { ResponseId }, request.PublisherKey); } catch (Exception ex) { prefilledanswerRequest.AnswerInfo.SurveyQuestionAnswerList = Values; response = Implementation.SetSurveyAnswer(prefilledanswerRequest); response.Status = "Created"; return(response); } Values.Remove(Responsekey); if (updatedtime.Key != null) { Values.Remove(updatedtime.Key); } if (fkey.Key != null) { Values.Remove(fkey.Key); } prefilledanswerRequest.AnswerInfo.SurveyQuestionAnswerList = Values; Dictionary <string, string> ErrorMessageList = new Dictionary <string, string>(); string Xml = Implementation.CreateResponseXml(prefilledanswerRequest, SurveyBOList); // ErrorMessageList = Implementation.ValidateResponse(SurveyBOList, prefilledanswerRequest); // if (fkey.Key != null) { try { var survey = Implementation.GetSurveyResponseById(new List <string> { fkey.Value }, request.PublisherKey); } catch (Exception ex) { SurveyResponseBO surveyresponsebO = new SurveyResponseBO(); surveyresponsebO.SurveyId = SurveyBOList[0].ParentId; surveyresponsebO.ResponseId = fkey.Value.ToString(); surveyresponsebO.XML = " "; surveyresponsebO.Status = 3; surveyresponsebO.RecrodSourceId = (int)ValidationRecordSourceId.MA; surveyresponsebO.DateUpdated = DateTime.Now; surveyresponsebO.DateCreated = surveyresponsebO.DateUpdated; surveyresponsebO.DateCompleted = surveyresponsebO.DateUpdated; surveyresponsebO = Implementation.InsertSurveyResponseApi(surveyresponsebO); } } if (ErrorMessageList.Count() > 0) { response = new PreFilledAnswerResponse(); response.ErrorMessageList = ErrorMessageList; response.ErrorMessageList.Add("SurveyId", request.SurveyId.ToString()); response.ErrorMessageList.Add("ResponseId", ResponseId); response.Status = ((Epi.Web.BLL.SurveyResponse.Message) 1).ToString(); Implementation.InsertErrorLog(response.ErrorMessageList); } SurveyResponseBO surveyresponseBO = new SurveyResponseBO(); SurveyResponseBO SurveyResponse = new SurveyResponseBO(); UserAuthenticationRequestBO UserAuthenticationRequestBO = new UserAuthenticationRequestBO(); surveyresponseBO.SurveyId = request.SurveyId.ToString(); surveyresponseBO.ResponseId = ResponseId.ToString(); surveyresponseBO.XML = Xml; System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); if (updatedtime.Key != null) { surveyresponseBO.DateUpdated = dateTime.AddMilliseconds(Convert.ToDouble(updatedtime.Value.ToString())).ToLocalTime(); surveyresponseBO.DateCompleted = dateTime.AddMilliseconds(Convert.ToDouble(updatedtime.Value.ToString())).ToLocalTime(); } else { surveyresponseBO.DateUpdated = DateTime.Now; surveyresponseBO.DateCompleted = DateTime.Now; } if (fkey.Key != null) { surveyresponseBO.RelateParentId = fkey.Value; } surveyresponseBO.Status = 3; SurveyResponse = Implementation.UpdateSurveyResponse(surveyresponseBO); UserAuthenticationRequestBO = Web.Common.ObjectMapping.Mapper.ToBusinessObject(ResponseId); Implementation.SavePassCode(UserAuthenticationRequestBO); //return Response string ResponseUrl = ConfigurationManager.AppSettings["ResponseURL"]; response = new PreFilledAnswerResponse(Web.Common.ObjectMapping.Mapper.ToDataTransferObjects(UserAuthenticationRequestBO)); response.SurveyResponseUrl = ResponseUrl + UserAuthenticationRequestBO.ResponseId; response.Status = ((Epi.Web.BLL.SurveyResponse.Message) 2).ToString(); return(response); } catch (Exception ex) { PassCodeDTO DTOList = new PassCodeDTO(); response = new PreFilledAnswerResponse(DTOList); if (response.ErrorMessageList != null) { response.ErrorMessageList.Add("Failed", "Failed to insert Response"); } response.Status = ((BLL.SurveyResponse.Message) 1).ToString(); return(response); } }