public ActionResult Save(Product product) { HttpClient httpClient = HttpClientHelper.Create(base.ApiUrl); var jsonValue = JsonSerializer.SerializeToString<Product>(product); string result = httpClient.Insert(jsonValue); return RedirectToAction("Index", "Product"); }
public HttpResponseMessage Create(Product entity) { try { ProductServiceInstance.Insert<Product, EPProduct>(entity); var response = Request.CreateResponse<Product>(HttpStatusCode.Created, entity); //string uri = Url.Link("product", new { id = p.ID }); //response.Headers.Location = new Uri(uri); return response; } catch (System.Exception ex) { //记录异常日志信息 var errorHandler = ErrorHandlerFactory.Create("插入产品信息发生异常!", 1003); LogHelper.Error(errorHandler.GetInfo(), ex); //throw new WebFaultException<ErrorHandler>(errorHandler, HttpStatusCode.BadRequest); throw ex; } }
public ActionResult Update(Product entity) { HttpClient httpClient = HttpClientHelper.Create(base.ApiUrl); IList<Product> entityList = new List<Product>(); entityList.Add(entity); var jsonValue = JsonSerializer.SerializeToString<IList<Product>>(entityList); ViewData["U_Product_Rows"] = jsonValue; string result = httpClient.Update(jsonValue); return RedirectToAction("Index", "Product"); }
public ActionResult Create() { ViewData["PRODUCT_ADD_OR_EDIT"] = "A"; var model = new Product(); return PartialView("ProductForm", model); }
public HttpResponseMessage Update(Product entity) { try { ProductServiceInstance.Update<Product, EPProduct>(entity); var response = Request.CreateResponse<string>(HttpStatusCode.Created, "更新产品数据成功!", "application/json"); return response; } catch (System.Exception ex) { //记录异常日志信息 var errorHandler = ErrorHandlerFactory.Create("更新产品信息发生异常!", 1004); LogHelper.Error(errorHandler.GetInfo(), ex); //throw new WebFaultException<ErrorHandler>(errorHandler, HttpStatusCode.BadRequest); throw ex; } }