public HttpResponseMessage InsertWith(Order entity, string type) { try { OrderServiceInstance.InsertWith(entity); var response = Request.CreateResponse<Order>(HttpStatusCode.Created, entity, "application/json"); 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 HttpResponseMessage Update(Order entity) { try { OrderServiceInstance.Update<Order, EPOrder>(entity); var response = Request.CreateResponse<Order>(HttpStatusCode.Accepted, entity); 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; } }
/// <summary> /// 插入订单,并更新产品记录 /// </summary> /// <param name="order"></param> public void InsertWith(Order order) { //插入订单 this.Insert<Order, EPOrder>(order); //更新产品主记录的订单数 IProductService productService = base.Container.GetInstance<IProductService>(); productService.Initialize(base.Container, base.Session); Product product = productService.GetById<Product, EPProduct>(order.ProductId); //暂时注释,用以表述多事务提交 //product.OrderCount = (product.OrderCount == null) ? 1: product.OrderCount + 1; productService.Update<Product, EPProduct>(product); }