public Stream GetImage(string idfile)
        {
            IBusinessService businessService        = Factory.Create <IBusinessService>(Keywords.UPLOADEDFILE, ClassType.clsTypeBusinessService);
            OperationResult  result                 = businessService.Get(idfile);
            UploadedFileForm uploadedFileForm       = new UploadedFileForm();
            UploadedFileFormDataConverter converter = new UploadedFileFormDataConverter();

            converter.PopulateForm(result.Data, uploadedFileForm);

            FileStream fs = File.OpenRead(Path.Combine(HostingEnvironment.MapPath("~/Resources/Uploads"), uploadedFileForm.TargetFileName));

            WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
            return(fs);
        }
        public string UploadFileWithTarget(string filename, string targetFilename, Stream stream)
        {
            OperationResult result = new OperationResult(true);

            try
            {
                string FilePath = Path.Combine(HostingEnvironment.MapPath("~/Resources/Uploads"), targetFilename);

                int length = 0;
                using (FileStream writer = new FileStream(FilePath, FileMode.Create))
                {
                    int readCount;
                    var buffer = new byte[8192];
                    while ((readCount = stream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        writer.Write(buffer, 0, readCount);
                        length += readCount;
                    }
                }


                IBusinessService businessService = Factory.Create <IBusinessService>(Keywords.UPLOADEDFILE, ClassType.clsTypeBusinessService);
                object           dataObject      = Factory.Create <object>(Keywords.UPLOADEDFILE, ClassType.clsTypeDataModel);

                UploadedFileForm formUpload = new UploadedFileForm();
                formUpload.FileSize         = length;
                formUpload.OriginalFileName = filename;
                formUpload.TargetFileName   = targetFilename;
                formUpload.UserId           = 1;
                formUpload.UploadedDate     = DateTime.Now;

                UploadedFileFormDataConverter formDataConverter = new UploadedFileFormDataConverter();
                formDataConverter.PopulateData(formUpload, dataObject);

                result = businessService.Add(dataObject);
            }
            catch (Exception err)
            {
                result = new OperationResult(false, err);
            }

            return(Serializer.Json.Serialize(result));
        }