public async Task <IActionResult> Create([Bind("Id,GameId,DatePlayed")] GamePlayed gamePlayed) { if (ModelState.IsValid) { _context.Add(gamePlayed); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Edit), new { id = gamePlayed.Id })); } ViewData["GameId"] = new SelectList(_context.Games, "Id", "Name", gamePlayed.GameId); return(View(gamePlayed)); }
public async Task <Unit> Handle(AttachImageToGame request, CancellationToken cancellationToken) { if (request.Content.Length > 0) { var gameImage = new GameImage { Id = Guid.NewGuid(), FileName = request.FileName, GameId = request.GameId }; if (_settings.Local) { if (!Directory.Exists(_imagePath)) { Directory.CreateDirectory(_imagePath); } File.WriteAllBytes(Path.Combine(_imagePath, $"{request.GameId}_{gameImage.Id}.jpg"), request.Content); } else { await _mediator.Send(new ResizeImagesAndStore { ImageContent = request.Content, GameId = request.GameId, ImageId = gameImage.Id }, cancellationToken); } _context.Add(gameImage); await _context.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public async Task <Unit> Handle(AssignGenresToTitle request, CancellationToken cancellationToken) { var existingAssociations = _context.TitleGenres.Where(tg => tg.TitleId == request.TitleId).ToList(); List <Guid> associated = new List <Guid>(); foreach (var name in request.Genres.Distinct()) { var genre = await _mediator.Send(new RegisterGenre { Name = name }, cancellationToken); if (_context.TitleGenres .SingleOrDefault(tg => tg.TitleId == request.TitleId && tg.GenreId == genre) == null) { _context.Add(new TitleGenre { TitleId = request.TitleId, GenreId = genre }); await _context.SaveChangesAsync(cancellationToken); } associated.Add(genre); } await RemoveUnusedAssociations(cancellationToken, existingAssociations, associated); return(Unit.Value); }
public async Task <IActionResult> Create([Bind("Id,Name")] Game game) { if (ModelState.IsValid) { _context.Add(game); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(game)); }
private PlatformGame RegisterGameWithPlatform(RegisterGame request, Game game) { var existing = _context.PlatformGames.SingleOrDefault(pg => pg.GameId == game.Id && pg.PlatformId == request.Platform); if (existing == null) { var platformGame = new PlatformGame() { GameId = game.Id, Code = request.Code, PlatformId = request.Platform, Registered = DateTime.UtcNow }; _context.Add(platformGame); return(platformGame); } return(existing); }
public async Task <Unit> Handle(AttachImageToGame request, CancellationToken cancellationToken) { if (!Directory.Exists(_imagePath)) { Directory.CreateDirectory(_imagePath); } if (request.Content.Length > 0) { await using var fileStream = new FileStream(Path.Combine(_imagePath, request.FileName.PrepareFileName()), FileMode.Create); await request.Content.CopyToAsync(fileStream, cancellationToken); _context.Add(new PlatformGameImage { FileName = request.FileName.PrepareFileName(), PlatformGameId = request.Id }); await _context.SaveChangesAsync(cancellationToken); } return(Unit.Value); }
public bool Verify(string email) { if (!string.IsNullOrEmpty(email)) { var user = _context.Users.SingleOrDefault(u => u.Email == email); if (user == null) { user = new User { Email = email, TenantId = Guid.NewGuid() }; _context.Add(user); _context.SaveChanges(); } return(true); } return(false); }