public string UpdateUploadedFile(UploadedFileForm uploadedFileForm)
        {
            DefaultController defaultController = new DefaultController(UploadedFileService.Keywords.UPLOADEDFILE);

            defaultController.FormValidator = new UploadedFileFormValidator();

            OperationResult result = defaultController.Update(uploadedFileForm);

            return(Serializer.Json.Serialize(result));
        }
        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));
        }
Example #4
0
        public ValidationResult Validate(DataForm form)
        {
            ValidationResult result           = new ValidationResult(true);
            UploadedFileForm uploadedFileForm = (UploadedFileForm)form;

            if (uploadedFileForm.OriginalFileName.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Original File Name can not be empty";
            }

            if (uploadedFileForm.TargetFileName.Length == 0)
            {
                result.Result       = false;
                result.ErrorMessage = "Target File Name can not be empty";
            }

            return(result);
        }