public Upload Upload(CsvViewModel csv) { var relativePath = Path.Combine("Userfile", new Random().Next().ToString()); var fullPath = Path.Combine(_hosting.WebRootPath, relativePath); _csvHandler.StoreCsvAsFile(fullPath, csv.Csv); using var stream = new FileStream(fullPath, FileMode.Open); var hashValue = _protector.HashMd5(stream); if (!_repository.GetAll().Any(p => p.HashName == hashValue)) { _csvHandler.SaveCsv(csv.Csv.FileName, relativePath, hashValue, DateTime.Now.ToString(CultureInfo.InvariantCulture)); return(new Upload() { Path = fullPath, Success = true }); } stream.Close(); _csvHandler.Delete(fullPath); return(new Upload() { Path = null, Success = false }); }