public string Put()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();
            DicomDbContext dbContextDicom            = new DicomDbContext(connStringPACSServer);
            RbacUser       currentUser = HttpContext.Session.Get <RbacUser>("currentuser");
            string         inputSting  = this.ReadPostData();

            try
            {
                //if(inputSting !=null && reqType="putToolData")
                //{
                object clientData = DanpheJSONConvert.DeserializeObject <object>(inputSting);

                JObject obj = JObject.Parse(inputSting);


                var FileToolData = obj["FileToolData"].ToString();
                var DicomFileId  = int.Parse(obj["DicomFileId"]["dicomFileId"].ToString());

                DicomFileInfoModel getDataForUpdate = dbContextDicom.DicomFiles.Where(d => d.DicomFileId == DicomFileId).FirstOrDefault <DicomFileInfoModel>();

                getDataForUpdate.FileToolData = FileToolData;
                getDataForUpdate.ModifiedBy   = currentUser.UserId;
                getDataForUpdate.ModifiedOn   = DateTime.Now;
                dbContextDicom.DicomFiles.Attach(getDataForUpdate);
                dbContextDicom.Entry(getDataForUpdate).Property(u => u.CreatedOn).IsModified = true;
                dbContextDicom.Entry(getDataForUpdate).State = EntityState.Modified;
                dbContextDicom.SaveChanges();
                responseData.Results = getDataForUpdate.DicomFileId;
                responseData.Status  = "OK";
                //}
                //else{
                //        responseData.Status = "Failed";
                //        responseData.Results = "input data is not available";
                //    }
            }
            catch (Exception ex)
            {
                responseData.Status = "Failed";
            }
            return(DanpheJSONConvert.SerializeObject(responseData));
        }
 public static void InsertFileInfoData(DicomFileInfoModel fileInfo, DicomDbContext dcmdbContext)
 {
     //dcmWrapObj.FileInfo.FileName = dcmWrapObj.FileInfo.SOPInstanceUID;
     ///dcmWrapObj.FileInfo.FilePath = path;
     try
     {
         fileInfo.CreatedOn = DateTime.Now;
         dcmdbContext.DicomFiles.Add(fileInfo);
         dcmdbContext.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
     }
 }
        public string Post()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            responseData.Status = "OK";

            try
            {
                string basepath = ConfigurationManager.AppSettings["DestinationPathAPI"];

                string  ipDataString = this.ReadPostData();
                JObject obj          = JObject.Parse(ipDataString);
                string  data         = (string)obj["fileData"];
                // ImageQueueModel ImgQObj = JsonConvert.DeserializeObject<ImageQueueModel>(imgData);

                //string jsonString = Encoding.ASCII.GetString(data.ToArray());

                byte[] byteArray = Encoding.ASCII.GetBytes(data);

                //Stream reqStream = Request.Body;
                MemoryStream inMemoryStream = new MemoryStream(byteArray);
                Request.Body.CopyTo(inMemoryStream);
                string             jsonString = Encoding.ASCII.GetString(inMemoryStream.ToArray());
                DicomWrapperVM     dcmWrapObj = JsonConvert.DeserializeObject <DicomWrapperVM>(jsonString);
                DicomFileInfoModel fileInfo   = dcmWrapObj.FileInfo;

                int patstudyId = 0;
                int seriesId   = 0;



                DicomDbContext dbContext = new DicomDbContext(connStringPACSServer);

                //check if particular SeriesInstanceUID is present or not.. if not present then only insert in PatientStudies table
                var StudyCheck = (from patstudy in dbContext.PatientStudies
                                  where patstudy.StudyInstanceUID == dcmWrapObj.PatientStudy.StudyInstanceUID
                                  select patstudy).FirstOrDefault();

                if (StudyCheck == null)
                {
                    InsertPatientStudiesData(dcmWrapObj.PatientStudy, dbContext);
                    patstudyId = dcmWrapObj.PatientStudy.PatientStudyId;
                }
                else
                {
                    patstudyId = StudyCheck.PatientStudyId;
                }


                //check if particular SeriesInstanceUID is present or not.. if not present then only insert in PatientStudies table
                var SeriesCheck = (from patSeries in dbContext.Series
                                   where patSeries.SeriesInstanceUID == dcmWrapObj.SeriesInfo.SeriesInstanceUID
                                   select patSeries).FirstOrDefault();

                if (SeriesCheck == null)
                {
                    dcmWrapObj.SeriesInfo.PatientStudyId = patstudyId;
                    InsertPatientSeriesData(dcmWrapObj.SeriesInfo, dbContext);
                    seriesId = dcmWrapObj.SeriesInfo.SeriesId;
                }
                else
                {
                    seriesId = SeriesCheck.SeriesId;
                }


                //can comment out below code of creating folders and saving file
                //folderpath format:  apistoragelocation\patname-studyid\seriesname-seriesid\sopinstanceid of file
                string studyFolderName = "", seriesFolderName = "";
                if (string.IsNullOrEmpty(dcmWrapObj.PatientStudy.PatientName))
                {
                    studyFolderName = "NA-" + patstudyId;
                }
                else
                {
                    studyFolderName = dcmWrapObj.PatientStudy.PatientName + "-" + patstudyId;
                }

                if (string.IsNullOrEmpty(dcmWrapObj.SeriesInfo.SeriesDescription))
                {
                    seriesFolderName = "NA-" + seriesId;
                }
                else
                {
                    seriesFolderName = dcmWrapObj.SeriesInfo.SeriesDescription + "-" + seriesId;
                }


                //! ? dcmWrapObj.PatientStudy.PatientName + "-" + patstudyId;
                string path     = basepath + @"\" + studyFolderName + @"\" + seriesFolderName;
                string fileName = path + @"\" + Path.GetFileName(dcmWrapObj.FileInfo.SOPInstanceUID);
                if (!(Directory.Exists(path)))
                {
                    Directory.CreateDirectory(path);
                }
                //Save the File to the Directory (Folder).
                System.IO.File.WriteAllBytes(fileName, dcmWrapObj.FileBytes);


                //get from table if data present... if not found then insert data in table DicomFiles
                var dicomfileCheck = (from f in dbContext.DicomFiles
                                      where f.SOPInstanceUID == dcmWrapObj.FileInfo.SOPInstanceUID
                                      select f).FirstOrDefault();
                responseData.Status = "OK";
                if (dicomfileCheck == null)
                {
                    DicomFileInfoModel dcmFile = new DicomFileInfoModel();
                    dcmFile.SeriesId       = seriesId;
                    dcmFile.FileBinaryData = dcmWrapObj.FileBytes;
                    dcmFile.FilePath       = fileName;
                    dcmFile.ROWGUID        = dcmWrapObj.FileInfo.ROWGUID;
                    dcmFile.SOPInstanceUID = dcmWrapObj.FileInfo.SOPInstanceUID;
                    dcmFile.CreatedOn      = DateTime.Now;

                    dbContext.DicomFiles.Add(dcmFile);
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + "exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }