public async Task <string> SaveOrder(OrderDto order)
        {
            string newOrderId = "";
            await Task.Factory.StartNew(() =>
            {
                lock (m_SyncObject)
                {
                    if (string.IsNullOrEmpty(order.Id))
                    {
                        newOrderId           = IdGenerator.GetNextOrderId();
                        order.Id             = newOrderId;
                        order.AcceptanceDate = DateTime.Now.Ticks;
                        order.DeliveringDate = DateTime.Now.AddDays(7).Ticks;
                        Order orderToSave    = order.FromDto();
                        _orderRepository.Add(orderToSave);
                    }
                    else
                    {
                        Order orderToSave = order.FromDto();
                        _orderRepository.Add(orderToSave);
                    }
                }
            });

            return(newOrderId);
        }
예제 #2
0
 public async Task <string> ApplyOrder(OrderDto order)
 {
     return(await _webSocketController.MakeOrderRequest(order.FromDto()));
 }
예제 #3
0
        private async Task <string> ProcessMakeOrderRequest(OrderRequestResponse request)
        {
            try
            {
                string clientID = request.Order.ClientInfo.Id;
                if (string.IsNullOrEmpty(clientID) || string.IsNullOrWhiteSpace(clientID))
                {
                    clientID = await _orderService.CustomerService.SaveCustomer(request.Order.ClientInfo.ToDto());
                }

                CustomerDto clientDto = await _orderService.CustomerService.GetCustomer(clientID);

                string result;

                if (clientDto == null)
                {
                    WebMessageBase response = new WebMessageBase("make_order");
                    response.Status  = MessageStatus.FAIL;
                    response.Message = "Client with ID: " + clientID + " not found";
                    result           = JsonConvert.SerializeObject(response, Formatting.Indented);
                    return(result);
                }

                request.Order.ClientInfo.Id = clientID;
                string orderId = await _orderService.SaveOrder(request.Order.ToDto());

                OrderDto orderDto = await _orderService.GetOrder(orderId);

                if (orderDto == null)
                {
                    WebMessageBase response = new WebMessageBase("make_order");
                    response.Status  = MessageStatus.FAIL;
                    response.Message = "Order with ID: " + request.Order.Id + " not found";
                    result           = JsonConvert.SerializeObject(response, Formatting.Indented);
                    return(result);
                }

                OrderRequestResponse orderResponse = new OrderRequestResponse("make_order", orderDto.FromDto());
                result = JsonConvert.SerializeObject(orderResponse, Formatting.Indented);
                return(result);
            }
            catch (Exception e)
            {
                WebMessageBase response = new WebMessageBase();
                response.Status  = MessageStatus.FAIL;
                response.Message = "Make order request error.";
                string result = JsonConvert.SerializeObject(response, Formatting.Indented);
                _log("During processing save_order request an error occured: " + e.Message);
                return(result);
            }
        }
예제 #4
0
        private async Task <string> ProcessGetOrderRequest(GetOrderRequest request)
        {
            try
            {
                OrderDto orderDto = await _orderService.GetOrder(request.Order);

                string result;

                if (orderDto == null)
                {
                    WebMessageBase response = new WebMessageBase("get_order");
                    response.Status  = MessageStatus.FAIL;
                    response.Message = "Order with ID: " + request.Order + " not found";
                    result           = JsonConvert.SerializeObject(response, Formatting.Indented);
                    return(result);
                }

                OrderRequestResponse orderResponse = new OrderRequestResponse("get_order", orderDto.FromDto());
                result = JsonConvert.SerializeObject(orderResponse, Formatting.Indented);
                return(result);
            }
            catch (Exception e)
            {
                WebMessageBase response = new WebMessageBase();
                response.Status  = MessageStatus.FAIL;
                response.Message = "Could not get order !";
                string result = JsonConvert.SerializeObject(response, Formatting.Indented);
                _log("During processing get_order request an error occured: " + e.Message);
                return(result);
            }
        }