public async void CreateVaegtKontrol() { //skal oprettes async int processOrdreNr = Model.SelectedPOSingleton.GetInstance().ActiveProcessOrdre.ProcessOrdreNr; int maxKontrol = await PersistencyVaegtKontrol.GetMax(processOrdreNr); int kontrolNr = ++maxKontrol; DateTime datoTid = DateTime.Now; VaegtKontrol aVaegtKontrol = new VaegtKontrol(processOrdreNr, kontrolNr, datoTid); PersistencyVaegtKontrol pVaegtKontrol = new PersistencyVaegtKontrol(); bool success = pVaegtKontrol.Post(aVaegtKontrol); if (success) { //feedback på succes. MessageDialog messageDialog = new MessageDialog($"Den nye VægtKontrol med nummer:{maxKontrol} blev oprettet", "Succes"); await messageDialog.ShowAsync(); } else { //feedback på fejl. message dialog MessageDialog messageDialog = new MessageDialog("Vægtkontrollen blev ikke oprettet", "Fejl"); await messageDialog.ShowAsync(); } }
public void TestMethod1() { //Arrange VaegtKontrolManager vaegtKontrolManager = new VaegtKontrolManager(); VaegtKontrol vK = new VaegtKontrol(1598290, 99, DateTime.Now); //Act int kontrollerFoer = vaegtKontrolManager.Get().Count(); bool result = vaegtKontrolManager.Post(vK); int kontrollerEfter = vaegtKontrolManager.Get().Count(); vaegtKontrolManager.Delete(vK.KontrolNr); //Assert Assert.IsTrue(result); Assert.AreEqual(kontrollerFoer + 1, kontrollerEfter); }
private VaegtKontrol ReadVaegts(SqlDataReader reader) { VaegtKontrol vaegtKontrol = new VaegtKontrol { ProcessOrdreNr = reader.GetInt32(0), KontrolNr = reader.GetInt32(1), DatoTid = reader.GetDateTime(2) }; return(vaegtKontrol); }
private VaegtKontrol ReadVaegtKontrol(SqlDataReader reader) { VaegtKontrol tempVaegtKontrol = new VaegtKontrol(); tempVaegtKontrol.ProcessOrdreNr = reader.GetInt32(0); tempVaegtKontrol.KontrolNr = reader.GetInt32(1); tempVaegtKontrol.DatoTid = reader.GetDateTime(2); return(tempVaegtKontrol); }
public static VaegtKontrol GetOne(int id) { VaegtKontrol vaegtKontrol = new VaegtKontrol(); using (HttpClient client = new HttpClient()) { Task <string> resTask = client.GetStringAsync(URI + $"/{id}"); string jsonStr = resTask.Result; vaegtKontrol = JsonConvert.DeserializeObject <VaegtKontrol>(jsonStr); } return(vaegtKontrol); }
//GETALL: api/VaegtKontrolManager public IEnumerable <VaegtKontrol> Get() { List <VaegtKontrol> liste = new List <VaegtKontrol>(); SqlConnection conn = new SqlConnection(ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand(GETALL, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { VaegtKontrol vaegtKontrol = ReadVaegtKontrol(reader); liste.Add(vaegtKontrol); } conn.Close(); return(liste); }
public IEnumerable <VaegtKontrol> GetVaegtKontrols(int ProcessOrderNr) { List <VaegtKontrol> liste = new List <VaegtKontrol>(); SqlConnection conn = new SqlConnection(ConnString); conn.Open(); SqlCommand cmd = new SqlCommand(GetVaegts, conn); cmd.Parameters.AddWithValue("@PONR", ProcessOrderNr); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { VaegtKontrol vaegtKontrol = ReadVaegts(reader); liste.Add(vaegtKontrol); } conn.Close(); return(liste); }
// GET: api/VaegtKontrolManager/5 public VaegtKontrol Get(int idNr) { VaegtKontrol vaegtKontrol = null; SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); SqlCommand cmd = new SqlCommand(GETONE, connection); cmd.Parameters.AddWithValue("@ID", idNr); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { vaegtKontrol = ReadVaegtKontrol(reader); } connection.Close(); return(vaegtKontrol); }
// POST: api/VaegtKontrolManager public bool Post(VaegtKontrol vaegtKontrol) { bool retValue = false; SqlConnection conn = new SqlConnection(ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand(INSERT, conn); cmd.Parameters.AddWithValue("@Process_Ordre_Nr", vaegtKontrol.ProcessOrdreNr); cmd.Parameters.AddWithValue("@Kontrol_Nr", vaegtKontrol.KontrolNr); cmd.Parameters.AddWithValue("@Dato_Tid", vaegtKontrol.DatoTid); int rowsAffected = cmd.ExecuteNonQuery(); retValue = rowsAffected == 1 ? true : false; conn.Close(); return(retValue); }
public bool Post(VaegtKontrol vaegtKontrol) { bool ok = true; using (HttpClient client = new HttpClient()) { String jsonStr = JsonConvert.SerializeObject(vaegtKontrol); StringContent content = new StringContent(jsonStr, Encoding.ASCII, "application/json"); Task <HttpResponseMessage> postAsync = client.PostAsync(URI, content); HttpResponseMessage resp = postAsync.Result; if (resp.IsSuccessStatusCode) { String jsonResStr = resp.Content.ReadAsStringAsync().Result; ok = JsonConvert.DeserializeObject <bool>(jsonResStr); } else { ok = false; } } return(ok); }
public UdviddetVaegtKontrol(VaegtKontrol vaegtKontrol) { VaegtKontrol = vaegtKontrol; Update(); }
// POST: api/VaegtKontrol public bool Post([FromBody] VaegtKontrol value) { return(manager.Post(value)); }