public Version AddVersion(string name, IFormFile file) { Material material = _materialRepository.GetMaterialByName(name); Version newVersion; if (material != null) { newVersion = new Version { Material = material, UploadTime = DateTime.Now, Size = file.Length, VersionCounter = material.Versions.Count() + 1 }; string path = _config.GetValue <String>("FilesPath:Type:ProjectDirectory") + material.Name + "_v" + (material.Versions.Count() + 1); using (var fileStream = new FileStream(path, FileMode.Create)) { file.CopyToAsync(fileStream); fileStream.Flush(); } _versionRepository.AddVersion(newVersion); _versionRepository.Save(); return(newVersion); } return(null); }