public DbResponse <int> OrderPlace(OrderPlaceModel model, string customerUserName) { try { var customerId = _db.Registration.CustomerIdByUserName(customerUserName); if (customerId == 0) { return(new DbResponse <int>(false, "Invalid User")); } model.CustomerId = customerId; if (model.OrderList.Count <= 0) { return(new DbResponse <int>(false, "No Product Found")); } if ((from item in model.OrderList let stock = _db.Product.GetQuantityBySetId(item.ProductQuantitySetId) where stock < item.Quantity select item).Any()) { return(new DbResponse <int>(false, "Product is stock out")); } _db.Order.PlaceAnOrder(model); //product stock update foreach (var item in model.OrderList) { _db.Product.QuantitySale(item.ProductQuantitySetId, item.Quantity); } _db.SaveChanges(); return(new DbResponse <int>(true, "Success", _db.Order.Order.OrderSn)); } catch (Exception e) { return(new DbResponse <int>(false, e.Message)); } }
public async Task <ApiResult> Place(OrderPlaceModel model) { GoodsCarDTO dto = new GoodsCarDTO(); var goods = await goodsService.GetModelAsync(model.GoodsId); if (goods == null) { return(new ApiResult { status = 0, msg = "商品不存在" }); } if (goods.Inventory < model.Number) { return(new ApiResult { status = 0, msg = "商品库存不足" }); } dto.GoodsId = model.GoodsId; dto.ImgUrl = goodsImgService.GetFirstImg(model.GoodsId); dto.Name = goods.Name; dto.Number = model.Number; dto.RealityPrice = goods.RealityPrice; dto.Price = goods.Price; User user = JwtHelper.JwtDecrypt <User>(ControllerContext); await orderApplyService.DeleteListAsync(user.Id); dto.UserId = user.Id; dto.GoodsAmount = dto.RealityPrice * dto.Number; long id = await orderApplyService.AddAsync(dto); if (id <= 0) { return(new ApiResult { status = 0, msg = "下单失败" }); } return(new ApiResult { status = 1, msg = "下单成功" }); }
public IActionResult PlaceOrder(OrderPlaceModel model) { var response = _order.OrderPlace(model, User.Identity.Name); return(Json(response)); }