Beispiel #1
0
        public ActionResult Upload(string tablename)
        {
            var rep      = new MetadataRepositoty();
            var metadata = rep.GetEntityMetadataByTableName("UploadedFiles", "dbo", 1);

            var result = new List <object>();

            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i] as HttpPostedFileWrapper;

                var newAttachment = metadata.New();
                newAttachment.Id               = Guid.NewGuid();
                newAttachment.ObjectId         = Guid.Empty;
                newAttachment.Name             = file.FileName;
                newAttachment.CreatedBy        = SecurityCache.CurrentUser.Name;
                newAttachment.CreatedDate      = DateTime.Now;
                newAttachment.Data             = ReadFile(file.InputStream);
                newAttachment.AttachmentLength = (int)Math.Round((decimal)file.ContentLength / 1024, 0);
                newAttachment.TableName        = tablename;
                metadata.Insert(newAttachment as DynamicEntity, ExternalMethodsCallMode.None);

                var res = new
                {
                    id               = newAttachment.Id,
                    name             = newAttachment.Name,
                    createdby        = newAttachment.CreatedBy,
                    createddate      = newAttachment.CreatedDate,
                    attachmentlength = newAttachment.AttachmentLength
                };

                result.Add(res);
            }

            StringBuilder sb      = new StringBuilder("[");
            bool          isFirst = true;

            foreach (var c in result)
            {
                if (!isFirst)
                {
                    sb.Append(",");
                }
                isFirst = false;
                sb.Append(ServiceStack.Text.JsonSerializer.SerializeToString(c));
            }

            sb.Append("]");

            return(new ContentResult
            {
                ContentType = "text/html",
                Content =
                    string.Format("{{\"success\":\"true\",\"result\":{0}}}"
                                  , sb.ToString())
            });
        }
        public ActionResult Download(string token, string filename)
        {
            var data = new byte[0];

            if (string.IsNullOrEmpty(filename))
                filename = "download";

            var rep = new MetadataRepositoty();
            var metadata = rep.GetEntityMetadataByTableName("UploadedFiles", "dbo", 1);

            var attachment = metadata.Get(FilterCriteriaSet.And.Equal(token, "Id")).FirstOrDefault();

            if (attachment == null)
                return new EmptyResult();

            return File(attachment.Data, "application/file", filename);
        }
Beispiel #3
0
        public ActionResult Download(string token, string filename)
        {
            var data = new byte[0];

            if (string.IsNullOrEmpty(filename))
            {
                filename = "download";
            }

            var rep      = new MetadataRepositoty();
            var metadata = rep.GetEntityMetadataByTableName("UploadedFiles", "dbo", 1);

            var attachment = metadata.Get(FilterCriteriaSet.And.Equal(token, "Id")).FirstOrDefault();

            if (attachment == null)
            {
                return(new EmptyResult());
            }

            return(File(attachment.Data, "application/file", filename));
        }
        public ActionResult Upload(string tablename)
        {
            var rep = new MetadataRepositoty();
            var metadata = rep.GetEntityMetadataByTableName("UploadedFiles", "dbo", 1);

            var result = new List<object>();

            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i] as HttpPostedFileWrapper;

                var newAttachment = metadata.New();
                newAttachment.Id = Guid.NewGuid();
                newAttachment.ObjectId = Guid.Empty;
                newAttachment.Name = file.FileName;
                newAttachment.CreatedBy = SecurityCache.CurrentUser.Name;
                newAttachment.CreatedDate = DateTime.Now;
                newAttachment.Data = ReadFile(file.InputStream);
                newAttachment.AttachmentLength = (int)Math.Round((decimal)file.ContentLength / 1024, 0);
                newAttachment.TableName = tablename;
                metadata.Insert(newAttachment as DynamicEntity, ExternalMethodsCallMode.None);

                var res = new
                {
                    id = newAttachment.Id,
                    name = newAttachment.Name,
                    createdby = newAttachment.CreatedBy,
                    createddate = newAttachment.CreatedDate,
                    attachmentlength = newAttachment.AttachmentLength
                };

                result.Add(res);
            }

            StringBuilder sb = new StringBuilder("[");
            bool isFirst = true;

            foreach (var c in result)
            {
                if (!isFirst)
                    sb.Append(",");
                isFirst = false;
                sb.Append(ServiceStack.Text.JsonSerializer.SerializeToString(c));
            }

            sb.Append("]");

            return new ContentResult
            {
                ContentType = "text/html",
                Content =
                    string.Format("{{\"success\":\"true\",\"result\":{0}}}"
                        , sb.ToString())
            };
        }