コード例 #1
0
        public ApiResultModel AddPatientFiles(FilesCustomModel oModel)
        {
            var strContent = JsonConvert.SerializeObject(oModel);
            var request    = ApiConsumerHelper.PostData("api/addPatientFile", strContent);

            var result = JsonConvert.DeserializeObject <ApiResultModel>(request);

            return(result);
        }
コード例 #2
0
        public async Task <HttpResponseMessage> AddPatientFiles(FilesCustomModel model)
        {
            UserFile patfile = new UserFile();

            try
            {
                //if (model.FileName == null || model.FileName == "" || !Regex.IsMatch(model.FileName.Trim(), "^[0-9a-zA-Z ]+$"))
                //{
                //    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid file name. Only letters and numbers are allowed." });
                //    return response;
                //}
                if (model.patientID == null || model.patientID == 0)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Invalid patient ID."
                    });
                    return(response);
                }

                /*  if (model.doctorID == null || model.doctorID == 0)
                 * {
                 *    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel { ID = 0, message = "Invalid doctor ID." });
                 *    return response;
                 * }*/
                if (model.fileContent == null)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "File is empty. "
                    });
                    response.ReasonPhrase = "Blank file is not allowed.";
                    return(response);
                }
                if (model.documentType == null || model.documentType == "")
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Please provide document type. "
                    });
                    return(response);
                }

                var    retBase64 = model.fileContent.Substring(model.fileContent.IndexOf("base64,") + 7);
                byte[] bytefilecontent;
                bytefilecontent = Convert.FromBase64String(retBase64);
                patfile         = db.UserFiles.Where(m => m.FileName == model.FileName.Trim() && m.active == true).FirstOrDefault();

                if (patfile == null)
                {
                    patfile           = new UserFile();
                    patfile.active    = true;
                    patfile.FileName  = model.FileName;
                    patfile.patientID = model.patientID;
                    patfile.cd        = System.DateTime.Now;
                    patfile.md        = System.DateTime.Now;
                    //patfile.doctorID = model.doctorID == -1 ? null : model.doctorID;
                    patfile.fileContent  = bytefilecontent;
                    patfile.documentType = model.documentType;
                    patfile.cb           = model.patientID.ToString();

                    db.UserFiles.Add(patfile);
                    await db.SaveChangesAsync();

                    response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel {
                        ID = patfile.fileID, message = ""
                    });
                    return(response);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "File already exists."
                    });
                    response.ReasonPhrase = "File already exists.";
                    return(response);
                }
            }
            catch (Exception ex)
            {
                return(ThrowError(ex, "Unable to upload file."));
            }
        }