Exemplo n.º 1
0
        public IActionResult Exercise1([FromBody] ApiRequest request)
        {
            var result = Exercise1Service.GetUser(request.url);

            if (result.IsOk)
            {
                Exercise1Response response = new Exercise1Response()
                {
                    name  = result.Value.name,
                    token = result.Value.token
                };
                return(Ok(new ApiResponse()
                {
                    passed = true, url = request.url, message = response
                }));
            }
            else
            {
                return(BadRequest(result.Errors));
            }
        }
Exemplo n.º 2
0
        public ResultValue <Exercise1Response> GetExercise1Response()
        {
            Exercise1Response resp = new Exercise1Response()
            {
                name  = "Qasim",
                token = "b674c919-a9aa-4669-af1e-ff6acfb88061"
            };

            return(Result.Ok(resp));

            //try
            //{
            //    var request = WebCommunication.CreateGetRequest(resource);
            //    var response = WebCommunication.Send(request);
            //    string responseFromServer = string.Empty;
            //    if (response.StatusCode == System.Net.HttpStatusCode.OK)
            //    {
            //        using (Stream dataStream = response.GetResponseStream())
            //        {

            //            StreamReader reader = new StreamReader(dataStream);

            //            responseFromServer = reader.ReadToEnd();

            //            return Result.Ok(JsonConvert.DeserializeObject<Exercise1Response>(responseFromServer));

            //        }
            //    }

            //    return Result.Failed<Exercise1Response>(Error.CreateFrom("External Server Communication Error", ErrorType.InternalServerError, response.StatusDescription));

            //}
            //catch(Exception ex)
            //{
            //    return Result.Failed<Exercise1Response>(Error.CreateFrom("External Server Communication Error", ex));
            //}
            //}
        }