public async Task <IActionResult> Edit(JogoEditViewModel model) { try { if (ModelState.IsValid) { var result = await _jogoService.EditJogoAsync(model); if (result.Succeeded) { ViewBag.alerts = new AlertViewModel { Type = GeneralConstants.SUCCESS, Text = result.Message }; } else { ViewBag.alerts = new AlertViewModel { Type = GeneralConstants.ERROR, Text = result.Message }; } } return(View(model)); } catch (Exception ex) { _logger.LogInformation(ex.Message); return(View("Error", new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } }
public async Task <QueryResult <JogoEditViewModel> > EditJogoAsync(JogoEditViewModel model) { RestClient client = new RestClient(_myGamesAPIConfig.URL); RestRequest request = new RestRequest("api/jogo/{id}", Method.PUT); request.AddParameter("id", model.Id, ParameterType.UrlSegment); request.AddParameter("nome", model.Nome, ParameterType.QueryString); System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; //System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3; IRestResponse <string> response = await client.ExecuteAsync <string>(request); if (response.StatusCode == System.Net.HttpStatusCode.NoContent) { return(new QueryResult <JogoEditViewModel> { Succeeded = true, Result = model, Message = "Jogo editado com sucesso." }); } return(new QueryResult <JogoEditViewModel> { Succeeded = false, Result = model, Message = response.Data }); }