/// <summary> /// 创建订单 /// </summary> /// <param name="memberId"></param> /// <param name="Contacts"></param> /// <param name="P_Id_Count"></param> /// <returns></returns> public ResultModel <OrderModel> CreateOrder(Guid memberId, string Contacts, Dictionary <Guid, int> P_Id_Count) { var result = new ResultModel <OrderModel>(); //P_Id_Count 商品遍历处理 var order = new Order { ProductAmount = 100, Freight = 10, Amount = 110, Discount = 20, PaymentAmount = 90, Member_Id = memberId, Status = (int)OrderStatus.Created }; dbContext.Order.Add(order); var orderStatus = new OrderStatusChange { Operator_Id = memberId, Operator_Remark = "创建订单", Order_Id = order.Id, Status = order.Status }; dbContext.OrderStatusChange.Add(orderStatus); if (!dbContext.Save()) { result.Message = "下单失败"; return(result); } result.Data = order.Translate <Order, OrderModel>((input, output) => { output.StatusChanges = new List <OrderStatusChangeModel> { orderStatus.Translate <OrderStatusChange, OrderStatusChangeModel>() }; }); return(result); }
public async Task <IActionResult> Edit(string id, Order order) { if (id != order.Id) { return(NotFound()); } if (ModelState.IsValid) { try { order.LastUpdateTime = DateTime.Now; OrderStatusChange orderStatusChange = new OrderStatusChange() { OrderId = order.Id, OrderStatu = order.OrderStatu, Price = order.Price, Description = order.Description, CreateTime = order.LastUpdateTime, }; _context.OrderStatusChanges.Add(orderStatusChange); _context.Update(order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(order.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new { owerId = order.OwnerId })); } return(View(order)); }