public string TransferBatch(HttpRequestMessage req) { var postedString = req.Content.ReadAsStringAsync().Result; dynamic v = JArray.Parse(postedString); //dynamic d = JObject.Parse(Convert.ToString(postedString)); //string month = Convert.ToDateTime(d.month); JArray toCsv = new JArray(); JArray pushJob = new JArray(); foreach (var equipment in v) { JObject item = new JObject(); JObject itemPushJob = new JObject(); string indate = equipment.jobDate; string[] dateinarray = indate.Split(' '); // for pushing into Transit Database itemPushJob.Add(new JProperty("SerialNo", equipment.SerialNo)); itemPushJob.Add(new JProperty("EquipmentID", Convert.ToString(equipment.Equipment))); itemPushJob.Add(new JProperty("EquipmentDescription", Convert.ToString(equipment.EquipmentDescription))); if (equipment.ToJob == "") { itemPushJob.Add(new JProperty("TransferLocID", equipment.ToLocation)); } else if (equipment.ToLocation == "") { itemPushJob.Add(new JProperty("TransferLocID", equipment.ToJob)); } itemPushJob.Add(new JProperty("TransferLocName", equipment.TransferLocDescription)); itemPushJob.Add(new JProperty("jobDate", equipment.jobDate)); itemPushJob.Add(new JProperty("CreatedBY", equipment.CreatedBy)); itemPushJob.Add(new JProperty("CreatedTime", DateTime.Now.ToString())); itemPushJob.Add(new JProperty("PhysicalDate", DateTime.Now.ToShortDateString())); pushJob.Add(itemPushJob); } obj = new DSL(); try { //string updateStatus= obj.UpdatevEMLocationHistory(JArray.Parse(postedString)); string updateStatus = obj.UpdatevEMLocationHistoryV2(JArray.Parse(postedString)); if (updateStatus == "1") { int TransitDBUpdate = obj.SchdeuleJob(pushJob); if (TransitDBUpdate == 1) { int phyisycalDateUpdate = obj.updateEquipmentPhysicaDateViewpoint(pushJob); if (phyisycalDateUpdate == 1) { return("Success"); } else { return("Date_update_failed"); } } else { return("failed"); } } else if (updateStatus == "-1") { return("failed"); } else { //return faulty equipment status in batch return(updateStatus); } } catch (Exception ex) { return("failed"); } }
public string ScheduleBatch(HttpRequestMessage req) { var postedString = req.Content.ReadAsStringAsync().Result; dynamic v = JArray.Parse(postedString); //dynamic d = JObject.Parse(Convert.ToString(postedString)); //string month = Convert.ToDateTime(d.month); JArray toCsv = new JArray(); JArray pushJob = new JArray(); foreach (var equipment in v) { JObject item = new JObject(); JObject itemPushJob = new JObject(); //for converting it to CSV item.Add(new JProperty("Mth", DateTime.Today.ToString("MM/dd/yyyy"))); item.Add(new JProperty("Equipment", Convert.ToString(equipment.Equipment))); item.Add(new JProperty("ToJob", equipment.ToJob)); item.Add(new JProperty("ToLocation", equipment.ToLocation)); string indate = equipment.jobDate; string[] dateinarray = indate.Split(' '); item.Add(new JProperty("DateIn", DateTime.Today.ToString(dateinarray[0]))); item.Add(new JProperty("TimeIn", DateTime.Now.ToString(dateinarray[1]))); toCsv.Add(item); // for pushing into Transit Database itemPushJob.Add(new JProperty("SerialNo", equipment.SerialNo)); itemPushJob.Add(new JProperty("EquipmentID", Convert.ToString(equipment.Equipment))); itemPushJob.Add(new JProperty("EquipmentDescription", Convert.ToString(equipment.EquipmentDescription))); if (equipment.ToJob == "") { itemPushJob.Add(new JProperty("TransferLocID", equipment.ToLocation)); } else if (equipment.ToLocation == "") { itemPushJob.Add(new JProperty("TransferLocID", equipment.ToJob)); } itemPushJob.Add(new JProperty("TransferLocName", equipment.TransferLocDescription)); itemPushJob.Add(new JProperty("jobDate", equipment.jobDate)); itemPushJob.Add(new JProperty("CreatedBY", equipment.CreatedBy)); itemPushJob.Add(new JProperty("CreatedTime", DateTime.Now.ToString())); pushJob.Add(itemPushJob); } Console.WriteLine(toCsv); obj = new DSL(); try { string csv = obj.convertToCSV(toCsv); int fcount = Directory.GetFiles("\\\\DEV-VPOIN\\Viewpoint_EMAutoImport", "*.*", SearchOption.TopDirectoryOnly).Length; string date = DateTime.Now.ToString().Replace(':', '_').Replace('/', '-'); string filename = (fcount + 1) + "_" + date; File.WriteAllText("\\\\DEV-VPOIN\\Viewpoint_EMAutoImport\\Job_" + filename + ".csv", csv); int i = obj.SchdeuleJob(pushJob); if (i == 1) { return("Success"); } else { return("faliure"); } } catch (Exception ex) { return("failed"); } }