public async Task <RespBase <Customer_Resp> > Add(Customer_Req model)
        {
            var request = JsonConvert.SerializeObject(model);
            var content = new StringContent(request, Encoding.UTF8, "application/json");

            var client = new HttpClient();

            client.BaseAddress = new Uri(_urlBase);
            var url = string.Concat(_endPoint);

            var response = client.PostAsync(url, content).Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var result = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <RespBase <Customer_Resp> >(result));
            }

            return(new RespBase <Customer_Resp>
            {
                IsSuccess = false,
                Code = (int)response.StatusCode,
                Message = "Error"
            });
        }
예제 #2
0
 public ActionResult Add(Customer_Req customer)
 {
     if (customer.CustomerID == 0)
     {
         var response = Task.Run(() => proxy.Add(customer));
         return(Json(response, JsonRequestBehavior.AllowGet));
     }
     else
     {
         var response = Task.Run(() => proxy.Update(customer));
         return(Json(response, JsonRequestBehavior.AllowGet));
     }
 }