Beispiel #1
0
        public async Task <RespBase <Product_Resp> > Add(Product_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 <Product_Resp> >(result));
            }
            else
            {
                return(new RespBase <Product_Resp>
                {
                    IsSuccess = false,
                    Code = (int)response.StatusCode,
                    Message = "Error"
                });
            }
        }
 public ActionResult Add(Product_Req model)
 {
     if (model.ProductID == 0)
     {
         var response = Task.Run(() => proxy.Add(model));
         return(Json(response, JsonRequestBehavior.AllowGet));
     }
     else
     {
         var response = Task.Run(() => proxy.Update(model));
         return(Json(response, JsonRequestBehavior.AllowGet));
     }
 }