Exemplo n.º 1
0
 public HttpResponseMessage Post(pitDTO pResponse)
 {
     HttpRequestMessage request = this.Request;
     int pitId = 0;
     if (pResponse == null)
         throw new HttpResponseException(HttpStatusCode.NotAcceptable);
     try
     {
         #region create PIT record
         PIT p = new PIT
         {
             Latitude = pResponse.GeoLoc.Latitude,
             Longitude = pResponse.GeoLoc.Longitude,
             CreatedDate = DateTime.Now,
             UserId = pResponse.UserId
         };
         p = ParseResponse(ref p, pResponse.Responses.ToList());
         db.PITs.Add(p);
         db.SaveChanges();
         pitId = p.PITId;
         #endregion //create client survey record
     }
     catch (Exception e)
     {
         CommonLib.ExceptionUtility.LogException(CommonLib.ExceptionUtility.Application.General, e, "Post PIT; URI =" + this.Request.RequestUri.AbsoluteUri);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
     }
     var response = Request.CreateResponse(HttpStatusCode.Created, pResponse);
     response.Content = new StringContent("PIT_Id =" + pitId.ToString());
     return response;
 }
Exemplo n.º 2
0
 private PIT ParseResponse(ref PIT p, List<pitDTO.Response> responses)
 {
     foreach (pitDTO.Response r in responses)
     {
         //Question question = db.Questions.Where(q => q.QuestionId == r.QuestionId).FirstOrDefault();
         #region Set counts
         switch (r.QuestionId)
         {
             case 9://Model
                 p.Model = r.Answer;
                 break;
             case 10://Sex
                 Dictionary<string, string> dict = GetDictAnswer(r.Answer);
                 p.NoMale = GetCount(dict, "Male");
                 p.NoFemale = GetCount(dict, "Female");
                 p.NoUnable2DetermineSex = GetCount(dict, "Not Sure");
                 break;
             case 11://age
                 Dictionary<string, string> dictAge = GetDictAnswer(r.Answer);
                 p.NoLessthan18 = GetCount(dictAge, "Under 18");
                 p.No18to24 = GetCount(dictAge, "18 - 24");
                 p.No25to55 = GetCount(dictAge, "25 - 55");
                 p.NoOver55 = GetCount(dictAge, "55 Over");
                 p.NoUnable2DetermineAge = GetCount(dictAge, "Not Sure");
                 break;
             case 12://household
                 Dictionary<string, string> dictHH = GetDictAnswer(r.Answer);
                 p.NoIndividual = GetCount(dictHH, "Individual");
                 p.NoCouple = GetCount(dictHH, "Couple");
                 p.NoFamily = GetCount(dictHH, "Family");
                 p.NoUnable2DetermineHouseHold = GetCount(dictHH, "Not Sure");
                 break;
             case 13://Location
                 var loc = Classes.Utility.TypeofLoc.Where(l => l.Value == r.Answer).FirstOrDefault();
                 p.TypeOfLocation = loc.Key;
                 break;
         #endregion //Set counts
         }
     }
     return p;
 }