コード例 #1
0
        public async Task <QueryResult <string> > DeleteAmigoAsync(AmigoDeleteViewModel model)
        {
            RestClient  client  = new RestClient(_myGamesAPIConfig.URL);
            RestRequest request = new RestRequest("api/amigo/{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 = "Amigo deletado com sucesso."
                });
            }

            return(new QueryResult <string>
            {
                Succeeded = false,
                Message = response.Data
            });
        }
コード例 #2
0
        public async Task <IActionResult> Delete(AmigoDeleteViewModel model)
        {
            try
            {
                var result = await _amigoService.DeleteAmigoAsync(model);

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

                    model = await _amigoService.GetAmigoDeleteAsync(model.Id);

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
                return(View("Error", new ErrorViewModel {
                    RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
                }));
            }
        }