public OrderCreatingResult AddOrder(Order order) { var result = new OrderCreatingResult(); // 計算總價 order.TotalPrice = order.Amount * order.UnitPrice; // 將訂單資訊寫入資料庫 this.orderDataAccess.Add(order); result.IsSuccess = true; result.Order = order; return(result); }
public override OrderCreatingResult AddOrder(Order order) { var result = new OrderCreatingResult(); var validator = new OrderValidator(); var validationResult = validator.Validate(order); if (validationResult.IsValid) { result = this.orderService.AddOrder(order); } else { result.Message = string.Join("\r\n", validationResult.Errors.Select(e => e.ErrorMessage)); } return(result); }