public async Task <IActionResult> AddGame([FromBody] GameRegisterModel newGame) { if (!ModelState.IsValid) { return(BadRequest("Invalid Model")); } var gameInfo = _mapper.Map <GameInfo>(newGame); if (newGame.CoverImageUrl != null) { var fileName = $"images/Games/Covers/{Guid.NewGuid()}{Path.GetExtension(newGame.CoverImageUrl.FileName)}"; await _fileSaveSvc.SaveFile(fileName, newGame.CoverImageUrl); gameInfo.CoverImageURL = fileName; } if (newGame.MultimediaFiles != null && newGame.MultimediaFiles.Count != 0) { foreach (var image in newGame.MultimediaFiles) { var imageFileName = $"images/Games/{Guid.NewGuid()}{Path.GetExtension(image.FileName)}"; await _fileSaveSvc.SaveFile(imageFileName, image); gameInfo.MultiMedias.Add(imageFileName); } } await _gamesSvc.RegisterGameAsync(gameInfo); return(Ok()); }
public async Task <IActionResult> Add(ClientInsertModel clientDto) { _userId = Guid.Parse(User.Claims.FirstOrDefault(c => c.Type == "sub").Value); if (clientDto.Type.Equals("oauth-client") && clientDto.ClientLogo != null) { var fileName = $"images/Clients/{Guid.NewGuid()}{Path.GetExtension(clientDto.ClientLogo.FileName)}"; await _filesSvc.SaveFile(fileName, clientDto.ClientLogo); clientDto.LogoUri = fileName; } var pwd = _clientSvc.AddClient(clientDto, _userId); return(RedirectToAction(nameof(NewClient), new { pass = pwd })); }