Пример #1
0
        public async Task <Material> UploadNewMaterial(string fileName, Int32 categoryNameId, long length)
        {
            Material uploadedMaterial = new Material
            {
                MaterialDate  = DateTime.Now,
                MaterialName  = $"{fileName}",
                MatCategoryId = Convert.ToInt16(categoryNameId)
            };
            MaterialVersion version = new MaterialVersion
            {
                FileDate   = DateTime.Now,
                Material   = uploadedMaterial,
                FileName   = $"{fileName}",
                Size       = length,
                PathOfFile = _dir
            };

            await _unitOfWork.MaterialVersions.AddRangeAsync(new List <MaterialVersion> {
                version
            });

            await _unitOfWork.CommitAsync();

            return(uploadedMaterial);
        }
Пример #2
0
        public async Task <(byte[] mas, string fileType, string fileName)> GetDataForDownloadMaterialAsync(Guid mId)
        {
            IEnumerable <MaterialVersion> ActualList() => _unitOfWork.MaterialVersions
            .Find(m => m.Material.Id == mId)
            .ToList()
            .OrderByDescending(m => m.FileDate);

            MaterialVersion ActualVersion = ActualList().Select(m => m).FirstOrDefault();
            string          fileName      = ActualVersion.FileName;
            string          filePath      = ActualVersion.PathOfFile + "/" + fileName;
            string          fileType      = "application/octet-stream";

            byte[] mas = System.IO.File.ReadAllBytes(filePath);

            return(mas, fileType, fileName);
        }
Пример #3
0
        public async Task <MaterialVersion> UploadNewMaterialVersion(string fileName, Guid mId, long length)
        {
            MaterialVersion uploadedVersion = new MaterialVersion
            {
                FileDate   = DateTime.Now,
                FileName   = $"{fileName}",
                PathOfFile = _dir,
                Size       = length,
                Material   = await _unitOfWork.Materials.GetMaterialById(mId)
            };

            await _unitOfWork.MaterialVersions.AddRangeAsync(new List <MaterialVersion> {
                uploadedVersion
            });

            await _unitOfWork.CommitAsync();

            return(uploadedVersion);
        }