/// <summary> /// /// </summary> /// <param name="id">orderId</param> /// <returns></returns> public ActionResult CreateOrUpdateReturnRequest(int id) { var refundOrder = _refundOrderService.GetRefundOrderByOrderId(id); var refundOrderItems = _refundOrderItemService.GetAllRefundOrderItems(id); var orderItems = _orderService.GetAllOrderItems(id, null, null, null, null, null, null); if (orderItems == null) { return(new HttpUnauthorizedResult()); } var model = new RefundOrderModel(); if (refundOrder != null) { foreach (var item in orderItems) { SelectListItem selectItem = new SelectListItem(); selectItem.Selected = false; selectItem.Value = item.Id.ToString(); selectItem.Text = item.Product.Name; model.ChoseOrderItemIds = item.Id.ToString() + ','; model.SelectList.Add(selectItem); } foreach (var item in model.SelectList) { for (int i = 0; i < refundOrderItems.Count; i++) { if (item.Value == refundOrderItems[i].OrderItemId.ToString()) { item.Selected = true; } model.ChoseOrderItemIds = model.ChoseOrderItemIds + refundOrderItems[i].OrderItemId + ","; } } model.RefundOrderId = refundOrder.Id; model.OperatorEmail = refundOrder.OperatorEmail; model.OperatorId = refundOrder.OperatorId; model.ReasonForRefund = refundOrder.ReasonForRefund; model.RefundAmount = refundOrder.RefundAmount; model.OrderId = refundOrder.OrderId; } else { foreach (var item in orderItems) { SelectListItem selectItem = new SelectListItem(); selectItem.Selected = true; selectItem.Value = item.Id.ToString(); selectItem.Text = item.Product.Name; model.ChoseOrderItemIds = item.Id.ToString() + ','; model.SelectList.Add(selectItem); } model.OrderId = id; } return(View(model)); }
public ActionResult CreateOrUpdateReturnRequest(RefundOrderModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageReturnRequests)) { return(AccessDeniedView()); } if (ModelState.IsValid) { if (model.RefundOrderId > 0) { var refundOrder = _refundOrderService.GetRefundOrderById(model.RefundOrderId); refundOrder.ReasonForRefund = model.ReasonForRefund; refundOrder.RefundAmount = model.RefundAmount; refundOrder.OperatorId = _workContext.CurrentCustomer.Id; refundOrder.OperatorEmail = _workContext.CurrentCustomer.Email; refundOrder.OperateTime = DateTime.Now; _refundOrderService.UpdateRefundOrder(refundOrder); string[] orderItemIds = model.ChoseOrderItemIds.TrimEnd(',').Split(','); var refundOrderItems = _refundOrderItemService.GetAllRefundOrderItems(model.OrderId); for (int i = 0; i < refundOrderItems.Count; i++) { _refundOrderItemService.DeleteRefundOrderItem(refundOrderItems[i]); } foreach (var item in orderItemIds) { RefundOrderItem refundorderItem = new RefundOrderItem(); refundorderItem.OrderId = model.OrderId; refundorderItem.OrderItemId = Convert.ToInt32(item); _refundOrderItemService.InsertRefundOrderItem(refundorderItem); SuccessNotification("修改退货请求成功"); } } else { RefundOrder refundOrder = new RefundOrder(); refundOrder.OrderId = model.OrderId; refundOrder.ReasonForRefund = model.ReasonForRefund; refundOrder.RefundAmount = model.RefundAmount; refundOrder.OperatorId = _workContext.CurrentCustomer.Id; refundOrder.OperatorEmail = _workContext.CurrentCustomer.Email; refundOrder.OperateTime = DateTime.Now; _refundOrderService.InsertRefundOrder(refundOrder); string[] orderItemIds = model.ChoseOrderItemIds.TrimEnd(',').Split(','); foreach (var item in orderItemIds) { RefundOrderItem refundorderItem = new RefundOrderItem(); refundorderItem.OrderId = model.OrderId; refundorderItem.OrderItemId = Convert.ToInt32(item); _refundOrderItemService.InsertRefundOrderItem(refundorderItem); } var order = _orderService.GetOrderById(model.OrderId); order.OrderStatus = OrderStatus.Complete; _orderService.UpdateOrder(order); SuccessNotification("添加退货请求成功"); } return(RedirectToAction("List")); } else { var orderItems = _orderService.GetAllOrderItems(model.OrderId, null, null, null, null, null, null); if (orderItems == null) { return(new HttpUnauthorizedResult()); } foreach (var item in orderItems) { SelectListItem selectItem = new SelectListItem(); selectItem.Selected = true; selectItem.Value = item.Id.ToString(); selectItem.Text = item.Product.Name; model.SelectList.Add(selectItem); } model.RefundAmount = 0; } return(View(model)); }