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")); }
public async Task <bool> AddVersion(Database.Entities.Version version) { await _context.Versions.AddAsync(version); return(await _context.SaveChangesAsync() > 0); }