public PrintTag GetOne(string client_id) { PrintTag tag = new PrintTag(); ObjectId id = new ObjectId(); //if (LocalIP.Get() == server) //{ _client = new MongoClient(connectionString); _database = _client.GetDatabase("mdw+service"); var _collection = _database.GetCollection <BsonDocument>("printQueue"); var filter = Builders <BsonDocument> .Filter.Eq("client_id", client_id); var item = _collection.FindOneAndDelete(filter); if (item == null) { return(null); } if (item.Contains("epc")) { tag.epc = item.GetElement("epc").Value.AsString; } id = item.GetElement("_id").Value.AsObjectId; if (item.Contains("fields")) { var d = item.GetElement("fields").Value.AsBsonDocument.ToDictionary(); foreach (var elem in d) { string k = elem.Key.ToString(); string v = elem.Value.ToString(); tag.fields.Add(k, v); } } return(tag); }
// GET: api/PrintQueue/5 public IEnumerable <PrintTag> Get(string client_id, string printer_name) { List <PrintTag> printQueue = new List <PrintTag>(); //if (LocalIP.Get() == server) //{ _client = new MongoClient(connectionString); _database = _client.GetDatabase("mdw+service"); var _collection = _database.GetCollection <BsonDocument>("printQueue"); var filter = Builders <BsonDocument> .Filter.Eq("client_id", client_id) & Builders <BsonDocument> .Filter.Eq("printer_name", printer_name); var found = _collection.Find(filter).ToList(); foreach (BsonDocument item in found) { PrintTag tag = new PrintTag(); if (item.Contains("epc")) { tag.epc = item.GetElement("epc").Value.AsString; } if (item.Contains("fields")) { var d = item.GetElement("fields").Value.AsBsonDocument.ToDictionary(); foreach (var elem in d) { string k = elem.Key.ToString(); string v = elem.Value.ToString(); tag.fields.Add(k, v); } } printQueue.Add(tag); } //} //else //{ // var client = new RestSharp.RestClient("http://webservice.assetsapp.com/mdw/"); // var request = new RestSharp.RestRequest("api/PrintQueue?client_id={client_id}&printer_name={printer_name}", RestSharp.Method.GET); // request.AddUrlSegment("client_id", client_id); // request.AddUrlSegment("printer_name", printer_name); // RestSharp.IRestResponse<List<PrintTag>> responseLicense = client.Execute<List<PrintTag>>(request); // printQueue = responseLicense.Data; // var statusLicense = responseLicense.StatusDescription; // if (statusLicense != "OK") // return null; //} return(printQueue); }
public async Task <IHttpActionResult> Post([FromBody] PrintTag tag, string client_id, string printer_name) { //if (LocalIP.Get() == server) //{ List <PrintTag> printQueue = new List <PrintTag>(); _client = new MongoClient(connectionString); _database = _client.GetDatabase("mdw+service"); var _collection = _database.GetCollection <BsonDocument>("printQueue"); BsonDocument document = new BsonDocument(); document.Add("client_id", client_id); document.Add("printer_name", printer_name); if (!string.IsNullOrEmpty(tag.epc)) { document.Add("epc", tag.epc); } //foreach (var element in tag.fields) //{ // document.Add(element.Key, element.Value); //} if (tag.fields.Count > 0) { document.Add("fields", new BsonDocument(tag.fields)); } _collection.InsertOne(document); return(Ok()); //} //else //{ // var client = new RestSharp.RestClient("http://webservice.assetsapp.com/mdw/"); // var request = new RestSharp.RestRequest("api/PrintQueue?client_id={client_id}&printer_name={printer_name}", RestSharp.Method.POST); // request.AddUrlSegment("client_id", client_id); // request.AddUrlSegment("printer_name", printer_name); // request.AddHeader("Content-Type", "application/json"); // request.AddHeader("Authorization", "Bearer " + LoginServer()); // request.RequestFormat = DataFormat.Json; // request.AddBody(new { tag = tag }); // RestSharp.IRestResponse responseToken = client.Execute(request); // var statusToken = responseToken.StatusDescription; // if (statusToken != "OK") // return BadRequest(); // return Ok(); //} }
public PrintTagModel Create(PrintTag printTag) { if (printTag == null) { return(null); } return(new PrintTagModel() { Company = printTag.Company, PONum = printTag.PONum, POLine = printTag.POLine, QtyPerContainer = printTag.QtyPerContainer, Uom = printTag.Uom, TransactionQty = printTag.TransactionQty, TagQty = printTag.TagQty, NumberOfTags = printTag.NumberOfTags }); }