Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(JogoDeleteViewModel model)
        {
            try
            {
                var result = await _jogoService.DeleteJogoAsync(model);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.alerts = new AlertViewModel {
                        Type = GeneralConstants.ERROR, Text = result.Message
                    };

                    model = await _jogoService.GetJogoDeleteAsync(model.Id);

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
                return(View("Error", new ErrorViewModel {
                    RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <QueryResult <string> > DeleteJogoAsync(JogoDeleteViewModel model)
        {
            RestClient  client  = new RestClient(_myGamesAPIConfig.URL);
            RestRequest request = new RestRequest("api/jogo/{id}", Method.DELETE);

            request.AddParameter("id", model.Id, ParameterType.UrlSegment);

            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 <string>
                {
                    Succeeded = true,
                    Message = "Jogo deletado com sucesso."
                });
            }

            return(new QueryResult <string>
            {
                Succeeded = false,
                Message = response.Data
            });
        }