Inheritance: BaseEntityDTO
Esempio n. 1
0
        public async Task<IHttpActionResult> Upload()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                var paths = GetUploadPath();

                if (!Directory.Exists(paths.Item1))
                {
                    Directory.CreateDirectory(paths.Item1);
                }

                var uploadProvider = new UploadMultipartFormProvider(paths.Item1);
                var result = await Request.Content.ReadAsMultipartAsync(uploadProvider);
                var originalFileName = GetDeserializedFileName(result.FileData.First());

                var file = new FileDTO
                {
                    Description = originalFileName,
                    FilePath = paths.Item2 + result.FileData.First().LocalFileName.Replace(paths.Item1, ""),
                    Size = new FileInfo(result.FileData.First().LocalFileName).Length
                };

                var uploadedFile = fileService.Add(file);

                return Json(uploadedFile, BOT_SERIALIZER_SETTINGS);
            }
            catch (Exception e)
            {

                throw new ApplicationException(e.Message);
            }
        }
Esempio n. 2
0
 public static void Update(this File destination, FileDTO source)
 {
     destination.Description = source.Description;
 }