public async Task <IActionResult> AddServerOrder([FromBody] ServerOrder order) { Debug.WriteLine("Adding new order with frequency= " + order.Frequency + " , orderTarget= " + order.TargetAddress); if (!ModelState.IsValid) { return(BadRequest("Request body is not correct!")); } using (UnitOfWork unitOfWork = new UnitOfWork(this._databaseContext)) { unitOfWork.ServerOrderRepository.Add(order); await unitOfWork.Save(); } var addingServerProvider = new AddingOrderProvider < ServerJobDetailComposer <ServerOrderJob>, SimpleTriggerComposer, ServerOrderJob>( new ServerJobDetailComposer <ServerOrderJob>(order.Id, order.TargetAddress), new SimpleTriggerComposer(order.Frequency, order.Id)); await addingServerProvider.AddOrder(); return(new JsonResult(order.Id)); }
public async Task <string> CreateOrder(ClientOrder order) { string id = null; //Create a server order with extra properties ServerOrder s = new ServerOrder(); s.customer = order.customer; s.item = order.item; //Add meta data to the order s.OrderStatus = "in progress"; s.CreationDate = DateTime.UtcNow; //Get a Document client using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey)) { string pathLink = string.Format("dbs/{0}/colls/{1}", databaseId, collectionId); ResourceResponse <Document> doc = await client.CreateDocumentAsync(pathLink, s); //Return the created id id = doc.Resource.Id; } return(id); }
public async Task <string> UpdateOrderById(string id, ClientOrder order) { string result = null; //Get a Document client using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey)) { string pathLink = string.Format("dbs/{0}/colls/{1}", databaseId, collectionId); dynamic doc = client.CreateDocumentQuery <Document>(pathLink).Where(d => d.Id == id).AsEnumerable().FirstOrDefault(); if (doc != null) { ServerOrder s = doc; s.customer = order.customer; s.item = order.item; s.ModifiedDate = DateTime.UtcNow; //Update document using self link. ResourceResponse <Document> x = await client.ReplaceDocumentAsync(doc.SelfLink, s); result = x.StatusCode.ToString(); } } return(result); }
public ServerOrder GetOrderById(string id) { ServerOrder order = null; //Get a Document client using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey)) { string pathLink = string.Format("dbs/{0}/colls/{1}", databaseId, collectionId); dynamic doc = client.CreateDocumentQuery <Document>(pathLink).Where(d => d.Id == id).AsEnumerable().FirstOrDefault(); if (doc != null) { order = doc; } } return(order); }
public static SOrder MapServerOrderToSOrder(this ServerOrder order) { return(new SOrder(order.Id, order.Frequency, order.TargetAddress, order.Question)); }