public RequestResponse SerializeResponse(string jsonResponse)
        {
            JObject jo = JObject.Parse(jsonResponse);
            RequestResponse response = new RequestResponse();
            response.messageId = (string)jo["messageId"];
            JArray destinationResponses = null;
            try
            {
                destinationResponses = (JArray)jo["destinationResponses"];
            }catch
            {
                destinationResponses = null;
            }
            
            response.statusCode = (string) jo["statusCode"];
            response.statusDetail = (string)jo["statusDescription"];
            response.version = (string)jo["version"];
            if (destinationResponses != null)
            {
                foreach (JObject j in jo["destinationResponses"])
                {
                    DestinationResponse dresponse = new DestinationResponse();
                    dresponse.messageId = (string) j["messageId"];
                    dresponse.address = (string)j["address"];
                    dresponse.statusCode = (string) j["statusCode"];
                    dresponse.statusDetail = (string)j["statusDescription"];
                    dresponse.timeStamp = (string)j["timeStamp"];
                    response.DesinationResponses.Add(dresponse);
                }
            }

            return response;

        }
        RequestResponse Map(tblRequestResponce rp)
        {
            if (rp == null) return null;
            RequestResponse response = new RequestResponse
                                           {
                                               messageId = rp.MessageId,
                                               statusCode = rp.StatusCode,
                                               statusDetail = rp.StatusDetails,
                                               version = rp.Vesion,
                                           };
            foreach (var item in rp.tblRequestResponceDestination)
            {
                DestinationResponse dr = Map(item);
                response.DesinationResponses.Add(dr);
            }
            return response;


        }
 public int Save(RequestResponse entity)
 {
     tblRequestResponce tblresponse = new tblRequestResponce();
     tblresponse.DateCreated = DateTime.Now;
     tblresponse.MessageId = entity.messageId;
     tblresponse.ReferenceId = entity.ReferenceId;
     tblresponse.StatusCode = entity.statusCode;
     tblresponse.StatusDetails = entity.statusDetail;
     tblresponse.Vesion = entity.version;
     foreach (DestinationResponse edest in entity.DesinationResponses)
     {
         tblRequestResponceDestination dest = new tblRequestResponceDestination();
         dest.Address = edest.address;
         dest.DateCreated = DateTime.Now;
         dest.ResponseTimeStamp = edest.timeStamp;
         dest.StatusCode = edest.statusCode;
         dest.StatusDetails = edest.statusDetail;
         dest.MessageId = edest.messageId;
         tblresponse.tblRequestResponceDestination.Add(dest);
     }
     _ctx.tblRequestResponce.Add(tblresponse);
     _ctx.SaveChanges();
     return tblresponse.Id;
 }
        void  SaveResponse(RequestResponse response)
       {
           string path = Server.MapPath("~/") +"RequestDownload";
               string fileName =path+ "//Response.txt";
           if (!Directory.Exists(path))
           {
               DirectoryInfo di = Directory.CreateDirectory(path);
               FileStream fsnew = new FileStream(fileName, FileMode.Create);
               fsnew.Close();
           }
       
           FileStream fs = new FileStream(fileName, FileMode.Append,FileAccess.Write);
           StreamWriter sw = new StreamWriter(fs);
           sw.WriteLine("############################################################");
           sw.WriteLine("");
           sw.WriteLine("\t StatusDetail " + response.statusDetail);
           sw.WriteLine("\t MessageId    " + response.messageId);
           sw.WriteLine("\t StatusCode   " + response.statusCode);
           sw.WriteLine("");
           sw.WriteLine("***********************************************************");
           sw.Flush();
           sw.Close();
           fs.Close();

       }