Пример #1
0
        public ActionResult Create(MVCServiceClient.ViewModels.PlantDetailVM plant)
        {
            var client = PlantClient();

            if (ModelState.IsValid)
            {
                DTObjects.PlantDetail dto      = MVCServiceClient.ViewModels.PlantDetailVM.buildModel(plant);
                HttpResponseMessage   response = null;
                try
                {
                    response = client.PostAsJsonAsync("api/plants", dto).Result;
                    response.EnsureSuccessStatusCode();
                }
                catch (HttpRequestException)
                {
                    //if (response.StatusCode == HttpStatusCode.NotFound) // 404
                    //{
                    //    return View(plant);
                    //}

                    return(View(plant));
                }
                // return URI of the created resource.
                // return response.Headers.Location;
                return(RedirectToAction("Index"));
            }

            return(View(plant));
        }
Пример #2
0
        public ActionResult Details(string id)
        {
            HttpClient client = PlantClient();

            DTObjects.PlantDetail plant = GetPlantBySku(client, id);
            MVCServiceClient.ViewModels.PlantDetailVM ViewModel = ViewModels.PlantDetailVM.buildModel(plant);
            return(View(ViewModel));
        }