public HttpResponseMessage Create(HttpRequestMessage request, OrderViewModel orderVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { Order orderDb = new Order(); orderDb.UpdateOrder(orderVm); var listOrderDetails = new List <OrderDetail>(); foreach (var item in orderVm.OrderDetails) { listOrderDetails.Add(new OrderDetail() { ProductID = item.ProductID, Quantity = item.Quantity, Price = item.Price, SizeId = item.SizeId, }); } orderDb.OrderDetails = listOrderDetails; _orderService.Create(orderDb); _orderService.Save(); //push notification var annoucement = _orderService.GetDetail(orderDb.ID); ShopOnlineHub.PushToAllUsers(Mapper.Map <OrderViewModel>(annoucement), null); return request.CreateResponse(HttpStatusCode.Created, orderVm); } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
public JsonResult CreateOrder() { var orderSession = (OrderSession)Session[Common.CommonConstant.SesstionOrder]; var cartShopping = (List <ShoppingCartViewModel>)Session[Common.CommonConstant.SesstionCart]; Order orderDb = new Order(); orderDb.UpdateOrder(orderSession.orderVm); orderDb.Status = true; orderDb.TotalPayment = orderSession.totalPrice; _orderService.Create(orderDb); _orderService.Save(); //push hup var annoucement = _orderService.GetDetail(orderDb.ID); ShopOnlineHub.PushToAllUsers(Mapper.Map <OrderViewModel>(annoucement), null); foreach (var item in cartShopping) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderID = orderDb.ID; decimal price = 0; if (item.productViewModel.PromotionPrice.HasValue) { price = (decimal)item.productViewModel.PromotionPrice; } else { price = item.productViewModel.Price; } orderDetail.Price = price; orderDetail.Quantity = item.Quantity; orderDetail.ProductID = item.productViewModel.ID; _orderService.CreateDetail(orderDetail); _orderService.Save(); } Session[Common.CommonConstant.SesstionCart] = new List <ShoppingCartViewModel>(); Session[Common.CommonConstant.SesstionOrder] = new OrderSession(); Session[Common.CommonConstant.CountShopping] = new int(); return(Json(new { status = true, })); }