public OrderListModel Post(AddOrderModel addOrderModel) { _commandProcessor.Send( new AddOrderCommand( addOrderModel.CustomerName, addOrderModel.Description, DateTime.Parse(addOrderModel.DueDate))); return Get(); }
public string Run() { var client = new HttpClientGateway().Client(); try { client.BaseAddress = _baseAddres; var order = new AddOrderModel() { CustomerName = "Winnie the Pooh", Description = "Pot of Honey", DueDate = DateTime.UtcNow.ToString("o") }; string orderBody; XmlRequestBuilder.TryBuild(order, out orderBody); var requestMessage = CreateRequest("orders", new StringContent(orderBody)); var response = client.SendAsync(requestMessage).Result; response.EnsureSuccessStatusCode(); return response.Content.ReadAsStringAsync().Result; } catch (AggregateException ae) { foreach (var e in ae.Flatten().InnerExceptions) { Console.Write(e.Message); if (e.InnerException != null) Console.WriteLine(" : " + e.InnerException); else Console.WriteLine(); } } catch (Exception he) { Console.WriteLine("Exception talking to server: {0}", he); } finally { client.Dispose(); } return null; }
private string PostOrder(HttpClient client) { var order = new AddOrderModel() { CustomerName = "Winnie the Pooh", Description = "Pot of Honey", DueDate = DateTime.UtcNow.ToString("o") }; string orderBody; XmlRequestBuilder.TryBuild(order, out orderBody); var requestMessage = CreateRequest("orders", new StringContent(orderBody)); var response = client.SendAsync(requestMessage).Result; response.EnsureSuccessStatusCode(); return response.Content.ReadAsStringAsync().Result; }