public void AddCatchDB(string navn, string art, double vaegt, string sted, int uge) { const string insertCatch = "insert into catchfinal (navn, art, vaegt, sted, uge) values (@navn, @art,@vaegt,@sted,@uge)"; using (SqlConnection databaseConnection = new SqlConnection(connectionString)) { databaseConnection.Open(); using (SqlCommand insertCommand = new SqlCommand(insertCatch, databaseConnection)) { insertCommand.Parameters.AddWithValue("@navn", navn); insertCommand.Parameters.AddWithValue("@art", art); insertCommand.Parameters.AddWithValue("@vaegt", vaegt); insertCommand.Parameters.AddWithValue("@sted", sted); insertCommand.Parameters.AddWithValue("@uge", uge); using (SqlDataReader reader = insertCommand.ExecuteReader()) { List <Fangst> fangstliste = new List <Fangst>(); while (reader.Read()) { Fangst fa = ReadCatch(reader); fangstliste.Add(fa); } } } } }
public IList <Fangst> GetWeekCatchDB(int uge) { const string selectWeekCatchDB = "select * from catchfinal where uge=@uge"; using (SqlConnection databaseConnection = new SqlConnection(connectionString)) { databaseConnection.Open(); using (SqlCommand selectCommand = new SqlCommand(selectWeekCatchDB, databaseConnection)) { selectCommand.Parameters.AddWithValue("@uge", uge); using (SqlDataReader reader = selectCommand.ExecuteReader()) { IList <Fangst> fangtsugeList = new List <Fangst>(); if (!reader.HasRows) { return(null); } reader.Read(); Fangst fangst = ReadCatch(reader); fangtsugeList.Add(fangst); return(fangtsugeList); } } } }
public void InitializeTest() { _fangst = new Fangst() { Fisker = new Fisker() }; }
//fangst vha id private static async Task <Fangst> GetOneCatchAsync(string id) { using (HttpClient client = new HttpClient()) { string content = await client.GetStringAsync(uri + "/catch/" + id); Fangst cList = JsonConvert.DeserializeObject <Fangst>(content); return(cList); } }
/// <summary> /// Slet fangst /// </summary> /// <param name="id"></param> /// <returns></returns> private static async Task <Fangst> DeleteCatchAsync(string id) { using (HttpClient client = new HttpClient()) { var content = await client.DeleteAsync(uri + "/catches/" + id); Fangst c = JsonConvert.DeserializeObject <Fangst>(content.Content.ReadAsStringAsync().Result); return(c); } }
public void Name_MustReturn_draugLegacyId() { var fangst = new Fangst() { LegacyId = 2 }; var bilde = new Bilde(fangst); Assert.AreEqual("draug2.jpg", bilde.Navn); }
private static async Task <Fangst> PostCatchAsync(Fangst newFangst) { using (HttpClient client = new HttpClient()) { HttpContent content = new StringContent(JsonConvert.SerializeObject(newFangst)); content.Headers.ContentType = new MediaTypeHeaderValue("Application/json"); var result = await client.PostAsync(uri + "/catches", content); Fangst c = JsonConvert.DeserializeObject <Fangst>(result.Content.ReadAsStringAsync().Result); return(c); } }
public Fangst UpdateCatch(string id, Fangst fangst) { int idNumber = int.Parse(id); Fangst existingFangst = FangstListe.FirstOrDefault(b => b.Id == idNumber); if (existingFangst == null) { return(null); } existingFangst.Navn = fangst.Navn; existingFangst.Art = fangst.Art; existingFangst.Veagt = fangst.Veagt; existingFangst.Sted = fangst.Sted; existingFangst.Uge = fangst.Uge; return(existingFangst); }
public Fangst DeleteCatch(string id) { Fangst fangst = GetCatch(id); if (fangst == null) { return(null); } bool removed = FangstListe.Remove(fangst); if (removed) { return(fangst); } return(null); }
private static Fangst ReadCatch(IDataRecord reader) { int id = reader.GetInt32(0); string name = reader.GetString(1); string art = reader.GetString(2); double vaegt = reader.GetDouble(3); string sted = reader.GetString(4); int uge = reader.GetInt32(5); Fangst fangst = new Fangst() { Id = id, Navn = name, Art = art, Veagt = vaegt, Sted = sted, Uge = uge, }; return(fangst); }
public IList <Fangst> GetCatchesDB() { const string selectallcatches = "select * from catchfinal order by id"; using (SqlConnection databaseConnection = new SqlConnection(connectionString)) { databaseConnection.Open(); using (SqlCommand selectCommand = new SqlCommand(selectallcatches, databaseConnection)) { using (SqlDataReader reader = selectCommand.ExecuteReader()) { List <Fangst> catchList = new List <Fangst>(); while (reader.Read()) { Fangst fangst = ReadCatch(reader); catchList.Add(fangst); } return(catchList); } } } }
static FishService() { Fangst firstFangst = new Fangst() { Id = 1, Navn = "EbbeVand", Art = "Gedde", Veagt = 3.75, Sted = "Aresø", Uge = 2 }; FangstListe.Add(firstFangst); Fangst secondFangst = new Fangst() { Id = 2, Navn = "PerterStor", Art = "Ørred", Veagt = 1.55, Sted = "Emsø", Uge = 7 }; FangstListe.Add(secondFangst); Fangst thirdFangst = new Fangst() { Id = 3, Navn = "AndyBor", Art = "Skalle", Veagt = 0.35, Sted = "Vejlesø", Uge = 25 }; FangstListe.Add(thirdFangst); }
public Bilde(Fangst fangst) { _fangst = fangst; }
public Fangst AddCatch(Fangst fangst) { fangst.Id = _nextid++; FangstListe.Add(fangst); return(fangst); }
public void Name_MustReturn_draugLegacyId() { var fangst = new Fangst() {LegacyId = 2}; var bilde = new Bilde(fangst); Assert.AreEqual("draug2.jpg", bilde.Navn); }