public async Task <IActionResult> Add(AddTestViewModel test) { if (ModelState.IsValid) { //TODO: Verify movie file var movieBytes = await test.MovieFile.GetAsBytes(); var romBytes = await test.RomFile.GetAsBytes(); var topReference = await test.ReferenceScreenshotTop.GetAsPngBytes(); var bottomReference = await test.ReferenceScreenshotBottom.GetAsPngBytes(); var now = DateTimeOffset.UtcNow; var def = new TestDefinition { ActivelyTesting = true, AddedAt = now, AddedByUser = _currentUser.User, MovieUrl = await _fileStorageService.StoreMovie(movieBytes), MovieSha256 = SHA256Hash.HashBytes(movieBytes), Notes = test.Notes, ReferenceScreenshotTopUrl = await _fileStorageService.StoreScreenshot(topReference), ReferenceScreenshotBottomUrl = await _fileStorageService.StoreScreenshot(bottomReference), TestName = test.TestName, TestRom = new TestRom { AddedAt = now, AddedByUser = _currentUser.User, CodeUrl = test.CodeUrl, RomSha256 = SHA256Hash.HashBytes(romBytes), RomUrl = await _fileStorageService.StoreTestRom(romBytes) } }; await _context.AddAsync(def); await _context.SaveChangesAsync(); _logger.LogInformation("Added new TestDefinition {TestDefinitionId}, by user {UserId}", def.TestDefinitionId, _currentUser.User.UserId); return(RedirectToAction("View", new { id = def.TestDefinitionId })); } return(View(test)); }
public async Task <IActionResult> Add(AddMovieViewModel addMovie) { if (ModelState.IsValid) { //TODO: Verify movie file var movieBytes = new byte[addMovie.MovieFile.Length]; var movieStream = new MemoryStream(movieBytes); await addMovie.MovieFile.CopyToAsync(movieStream); //Calculate movie length by counting how many PadAndCircle are in the file, there are 234/second int padCount = 0; for (var i = 256; i < movieBytes.Length; i += 7) { if (movieBytes[i] == 0) { padCount++; } } var length = TimeSpan.FromSeconds(padCount / 234.0); var movie = new RomMovie { ActivelyTesting = true, AddedAt = DateTimeOffset.UtcNow, AddedByUser = _currentUser.User, CitraRegionValue = addMovie.CitraRegionValue, Description = addMovie.Description, Length = length, MovieUrl = await _fileStorageService.StoreMovie(movieBytes), MovieSha256 = SHA256Hash.HashBytes(movieBytes), Name = addMovie.Name, RomId = addMovie.RomId }; await _context.RomMovies.AddAsync(movie); await _context.SaveChangesAsync(); return(RedirectToAction("View", new { id = movie.RomMovieId })); } return(View(addMovie)); }