public void CreateMedicament_ReadMedicaments_GetTheCreatedMedicament_DeleteMedicament() { using (IDal dal = new Dal()) { //Create Dictionary<string, string> Attrs = new Dictionary<string, string>(); Attrs["Name"] = "Doliprane"; Attrs["Price"] = "20"; Attrs["Form"] = "Injectable"; Attrs["Description"] = "bla bla bla bla"; Medicament M = new Medicament { Name = Attrs["Name"], Price = float.Parse(Attrs["Price"]), Description = Attrs["Description"], Form = Attrs["Form"] }; dal.CreateMedicament(M); //Read List<Medicament> Ms = dal.ReadMedicaments(); Assert.IsNotNull(Ms); Assert.AreEqual(1, Ms.Count); Assert.AreEqual("Doliprane", Ms[0].Name); Assert.AreEqual(20, Ms[0].Price); Assert.AreEqual("Injectable", Ms[0].Form); Assert.AreEqual("bla bla bla bla", Ms[0].Description); //Delete dal.DeleteMedicament(M.Id); Assert.IsNotNull(Ms); //Read Ms = dal.ReadMedicaments(); Assert.AreEqual(0, Ms.Count); } }
public List<Medicament> GetMedicaments() { List<Medicament> list = new List<Medicament>(); string url = "http://medicament.ma/listing-des-medicaments/"; string xpathString = "//div[@class='pages catalogue']/ul/li/a"; getHtmlWeb = new HtmlWeb(); try { Console.WriteLine("Search for drugs begening "); Console.WriteLine("----------------------------------------------"); HtmlDocument htmlDoc = getHtmlWeb.Load(url); HtmlDocument drugInfo = null; Medicament medicament = null; int i; string[] attrs = new string[4]; foreach (var item in htmlDoc.DocumentNode.SelectNodes(xpathString)) { i = 0; drugInfo = getHtmlWeb.Load(item.GetAttributeValue("href", "")); medicament = new Medicament(); medicament.Name = drugInfo.DocumentNode.SelectSingleNode("//legend").InnerText; foreach (var info in drugInfo.DocumentNode.SelectNodes("//table/tr/td[@class='value']")) { attrs[i++] = info.InnerText; } medicament.Presentation = attrs[0]; medicament.Composition = attrs[2]; //medicament.Price = float.Parse() list.Add(medicament); return list; } } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("----------------------------------------------"); Console.WriteLine("Search is end"); return list; }
public void UpdateMedicament(Medicament M) { Medicament Med=Db.Medicaments.Find(M.Id); Med.Name = M.Name; Med.Price = M.Price; Med.Description = M.Description; Med.Form = M.Form; Db.SaveChanges(); }
public void CreateMedicament(Medicament M) { Db.Medicaments.Add(M); Db.SaveChanges(); }