Пример #1
0
        public DtoFile CreateFile(DtoFile e)
        {
            var file = fileRepository.Create(e.ToDalFile());

            uow.Commit();

            return(file.ToDtoFile());
        }
Пример #2
0
        public ActionResult EditFile(string title, long id)
        {
            if (!ReferenceEquals(title, null))
            {
                DtoFile file   = fileService.GetFileById(id);
                string  format = file.FileTypes.First().Format;

                fileService.UpdateFileTitle(title.Split('.')[0] + $".{format}", id);
            }
            return(Json(""));
        }
Пример #3
0
        /// <summary>
        /// Convert DtoFile to json ready format
        /// </summary>
        /// <param name="file">converting file</param>
        /// <param name="type">file type</param>
        /// <returns>Json File</returns>
        public static JsonGridObject ToGridObject(this DtoFile file, string type)
        {
            if (ReferenceEquals(file, null))
            {
                return(null);
            }

            return(new JsonGridObject
            {
                id = file.ID,
                data = new [] { SetIconPath(type), file.Title, file.FileTypes.First().TypeName, file.DateTime.ToString("D") }
            });
        }
Пример #4
0
 public async Task <ActionResult <DtoFile> > Post(DtoFile FileInput)
 {
     try
     {
         File F = _mapper.Map <File>(FileInput);
         _repository.Add(F);
         if (await _repository.SaveChangesAsync())
         {
             return(Created($"/api/file/", _mapper.Map <DtoFile>(F)));
         }
     }
     catch
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, ""));
     }
     return(BadRequest());
 }
Пример #5
0
        /// <summary>
        /// Convert Bll File entity to Dal entity
        /// </summary>
        /// <param name="file">bll entity</param>
        /// <returns>dal entity</returns>
        public static DalFile ToDalFile(this DtoFile file)
        {
            if (ReferenceEquals(file, null))
            {
                return(null);
            }

            return(new DalFile
            {
                ID = file.ID,
                Data = file.Data,
                DateTime = file.DateTime,
                Title = file.Title,
                FolderID = file.FolderID,
                FileTypes = new HashSet <DalFileType>(file.FileTypes.Select(item => item.ToDalFileType()))
            });
        }
Пример #6
0
        public async Task <ActionResult> UploadFiles(HttpPostedFileBase file, string ID, string mode)
        {
            if (!ReferenceEquals(file, null) && !string.IsNullOrEmpty(ID))
            {
                using (var fileData = new MemoryStream(new byte[file.InputStream.Length]))
                {
                    await file.InputStream.CopyToAsync(fileData);

                    long id;

                    long.TryParse(ID, out id);

                    string      format   = file.FileName.Split('.')[1];
                    DtoFileType fileType = fileTypeService.GetFileTypesByPredicate(fl => fl.Format.Equals(format)).FirstOrDefault();

                    if (ReferenceEquals(fileType, null))
                    {
                        fileType = fileTypeService.CreateFileType(new DtoFileType
                        {
                            Format   = format,
                            TypeName = file.ContentType
                        });
                    }

                    /*var data = new byte[file.InputStream.Length];
                     *
                     * fileData.Position = 0;
                     * for (int totalBytesCopied = 0; totalBytesCopied < fileData.Length;)
                     *  totalBytesCopied += fileData.Read(data, totalBytesCopied, Convert.ToInt32(fileData.Length) - totalBytesCopied);
                     */

                    DtoFile newFile = new DtoFile {
                        DateTime = DateTime.Now, Data = fileData.ToArray(), Title = file.FileName, FolderID = id, FileTypes = new[] { fileType }
                    };

                    fileService.CreateFile(newFile);
                }

                return(Json(new { state = true, name = file.FileName, size = file.ContentLength }));
            }

            return(Json(""));
        }
Пример #7
0
 public void UpdateFile(DtoFile e)
 {
     fileRepository.Update(e.ToDalFile());
     uow.Commit();
 }
Пример #8
0
 public void DeleteFile(DtoFile e)
 {
     fileRepository.Delete(e.ToDalFile());
     uow.Commit();
 }