Example #1
0
        public Material AddMaterial(Material material, IFormFile file)
        {
            Version newVersion;

            if (material != null)
            {
                newVersion = new Version
                {
                    Material       = material,
                    UploadTime     = DateTime.Now,
                    Size           = file.Length,
                    VersionCounter = 1
                };
                string path = _config.GetValue <String>("FilesPath:Type:ProjectDirectory") + material.Name + "_v1";
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    file.CopyToAsync(fileStream);
                    fileStream.Flush();
                }
                _materialRepository.AddMaterial(material);
                _versionRepository.AddVersion(newVersion);
                _materialRepository.Save();
                return(material);
            }
            return(null);
        }
Example #2
0
        public async Task <IActionResult> UploadNewVersion([FromForm] UploadDto uploadDto)
        {
            if (uploadDto.File.Length > 0)
            {
                var fileData = new FileData()
                {
                    Created   = DateTime.Now,
                    Extension = Path.GetExtension(uploadDto.File.FileName),
                    Name      = uploadDto.File.FileName.Replace(Path.GetExtension(uploadDto.File.FileName), ""),
                };

                using (var ms = new MemoryStream())
                {
                    uploadDto.File.CopyTo(ms);
                    var fileBytes = ms.ToArray();

                    fileData.Content = fileBytes;
                }

                await _repo.UploadFile(fileData);

                if (fileData.Id > 0)
                {
                    var newVersion = new Database.Entities.Version
                    {
                        Created     = DateTime.Now,
                        Major       = uploadDto.Major.Value,
                        Minor       = uploadDto.Minor.Value,
                        Patch       = uploadDto.Patch.Value,
                        Name        = uploadDto.Name ?? fileData.Name,
                        FileDataId  = fileData.Id,
                        ComponentId = uploadDto.ComponentId,
                        KindId      = uploadDto.KindId
                    };

                    await _repo.AddVersion(newVersion);

                    if (newVersion.Id > 0)
                    {
                        return(StatusCode((int)HttpStatusCode.Created));
                    }
                }
            }

            return(StatusCode((int)HttpStatusCode.InternalServerError, "Error Upload"));
        }