예제 #1
0
        public ActionResult Create(a_ProductViewModel a_Product)
        {
            if (ModelState.IsValid)
            {
                string a_ProductJSON = JsonConvert.SerializeObject(a_Product);
                var    buffer        = Encoding.UTF8.GetBytes(a_ProductJSON);
                var    byteContent   = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                string     API_END_POINT = API_URL + "api/a_ProductAPI/";
                HttpClient client        = new HttpClient();

                HttpResponseMessage response = client.PostAsync(API_END_POINT, byteContent).Result;

                string result  = response.Content.ReadAsStringAsync().Result.ToString();
                bool   success = bool.Parse(result);

                if (success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Something was happened.");
                    return(View(a_Product));
                }
            }
            return(View(a_Product));
        }
 public bool Put(a_ProductViewModel a_Product)
 {
     try
     {
         service.Updatea_Product(a_Product);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
 public bool Post(a_ProductViewModel a_Product)
 {
     try
     {
         service.CreateNewa_Product(a_Product);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #4
0
        public List <a_ProductViewModel> Geta_ProductList(string id)
        {
            var a_Products    = service.Geta_ProductList();
            var Lista_Product = new List <a_ProductViewModel>();

            foreach (var a_Product in a_Products)
            {
                var result = new a_ProductViewModel();
                result.ID   = a_Product.ID;
                result.Name = a_Product.Name;
                Lista_Product.Add(result);
            }
            return(Lista_Product);
        }
예제 #5
0
        // GET: a_Products/Details/{id}
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string              API_END_POINT = API_URL + "api/a_ProductAPI/Get/" + (id ?? 0);
            HttpClient          client        = new HttpClient();
            HttpResponseMessage response      = client.GetAsync(API_END_POINT).Result;

            string             result = response.Content.ReadAsStringAsync().Result.ToString();
            a_ProductViewModel Model  = JsonConvert.DeserializeObject <a_ProductViewModel>(result);

            if (Model == null)
            {
                return(HttpNotFound());
            }
            return(View(Model));
        }