public DtoFileType CreateFileType(DtoFileType e) { var fileType = fileTypeRepository.Create(e.ToDalFileType()); uow.Commit(); return(fileType.ToDtoFileType()); }
/// <summary> /// Convert Bll FileType entity to Dal entity /// </summary> /// <param name="fileType">bll entity</param> /// <returns>dal entity</returns> public static DalFileType ToDalFileType(this DtoFileType fileType) { if (ReferenceEquals(fileType, null)) { return(null); } return(new DalFileType { ID = fileType.ID, TypeName = fileType.TypeName, Format = fileType.Format }); }
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("")); }
public void UpdateFileType(DtoFileType e) { fileTypeRepository.Update(e.ToDalFileType()); uow.Commit(); }