Exemplo n.º 1
0
        public async Task <ActionResult> PutBook(BookViewModel bookViewModelook)
        {
            try
            {
                Book book = bookViewModelook.Extract();

                var content = new StringContent(JsonConvert.SerializeObject(book), Encoding.UTF8, "application/json");

                HttpClient          httpClient          = this.GetHttp();
                HttpResponseMessage httpResponseMessage = await httpClient.PostAsync("api/Book/PutBook", content);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    return(Json(new { success = true, message = String.Empty, redirecturl = "/Book/Index" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = httpResponseMessage.RequestMessage }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }