public static List <Stylists> GetAll() { List <Stylists> AllStylists = new List <Stylists> { }; SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM stylists;", conn); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { int stylistId = rdr.GetInt32(0); string stylistName = rdr.GetString(1); Stylists newStylists = new Stylists(stylistName, stylistId); AllStylists.Add(newStylists); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(AllStylists); }
public static Stylists Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM stylists WHERE id = @StylistsId;", conn); SqlParameter stylistsIdPara = new SqlParameter("@StylistsId", id.ToString()); cmd.Parameters.Add(stylistsIdPara); SqlDataReader rdr = cmd.ExecuteReader(); int foundStylistsId = 0; string foundStylistsName = null; while (rdr.Read()) { foundStylistsId = rdr.GetInt32(0); foundStylistsName = rdr.GetString(1); } Stylists foundStylists = new Stylists(foundStylistsName, foundStylistsId); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(foundStylists); }
public void Test_StylistEmptyAtFirst() { //Arrange, Act int result = Stylists.GetAll().Count; //Assert Assert.Equal(0, result); }
public void Test_Find_FindsStylistsInDatabase() { //Arrange Stylists testStylists = new Stylists("Jacob"); testStylists.Save(); //Act Stylists foundStylists = Stylists.Find(testStylists.GetId()); //Assert Assert.Equal(testStylists, foundStylists); }
public override bool Equals(System.Object otherStylists) { if (!(otherStylists is Stylists)) { return(false); } else { Stylists newStylists = (Stylists)otherStylists; bool idEquality = (this.GetId() == newStylists.GetId()); bool nameEquality = (this.GetName() == newStylists.GetName()); return(idEquality && nameEquality); } }
public void Test_Update_UpdatesStylistsInDatabase() { //Arrange string name = "Nick"; Stylists testStylists = new Stylists(name); testStylists.Save(); string newName = "Jacob"; //Act testStylists.Update("Jacob"); string result = testStylists.GetName(); //Assert Assert.Equal(newName, result); }
public void Test_Save_SaveStylistToDatabase() { //Arrange Stylists testStylists = new Stylists("Jacob"); testStylists.Save(); //Act List <Stylists> result = Stylists.GetAll(); List <Stylists> testList = new List <Stylists> { testStylists }; //Assert Assert.Equal(testList, result); }
public void Test_GetClients_RetrieveAllClientsWithinStylists() { //Arrange Stylists testStylists = new Stylists("Jacob"); testStylists.Save(); Clients firstClients = new Clients("Susan", testStylists.GetId()); firstClients.Save(); Clients secondClients = new Clients("Emma", testStylists.GetId()); secondClients.Save(); //Act List <Clients> testClientsList = new List <Clients> { firstClients, secondClients }; List <Clients> resultClientsList = testStylists.GetClients(); //Assert Assert.Equal(testClientsList, resultClientsList); }
public void Test_Delete_DeleteStylistFromDatabase() { //Arrange string name1 = "Gary"; Stylists testStylist1 = new Stylists(name1); testStylist1.Save(); string name2 = "Wallace"; Stylists testStylist2 = new Stylists(name2); testStylist2.Save(); Clients client1 = new Clients("Susan", testStylist1.GetId()); client1.Save(); Clients client2 = new Clients("Emma", testStylist2.GetId()); client2.Save(); //Act testStylist1.Delete(); List <Stylists> resultStylists = Stylists.GetAll(); List <Stylists> testStylists = new List <Stylists> { testStylist2 }; List <Clients> resultClients = Clients.GetAll(); List <Clients> clientsList = new List <Clients> { client2 }; //Assert Assert.Equal(testStylists, resultStylists); Assert.Equal(clientsList, resultClients); }
public void Dispose() { Clients.DeleteAll(); Stylists.DeleteAll(); }
public HomeModule() { Get["/"] = _ => View["index.cshtml"]; Get["/stylists"] = _ => { List <Stylists> AllStylists = Stylists.GetAll(); return(View["stylists.cshtml", AllStylists]); }; Get["/clients"] = _ => { List <Clients> AllClients = Clients.GetAll(); return(View["clients.cshtml", AllClients]); }; Get["/clients/new"] = _ => { List <Stylists> AllStylists = Stylists.GetAll(); return(View["/add_client.cshtml", AllStylists]); }; Get["/stylists/new"] = _ => { return(View["/add_stylist.cshtml"]); }; Post["/clients"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); Clients newClients = new Clients(Request.Form["client"], Request.Form["stylist_id"]); var selectedStylist = Stylists.Find(newClients.GetStylistId()); newClients.Save(); model.Add("stylist", selectedStylist); model.Add("client", newClients); return(View["client_added.cshtml", model]); }; Post["/stylists"] = _ => { Stylists newStylists = new Stylists(Request.Form["name"]); newStylists.Save(); return(View["stylist_added.cshtml", newStylists]); }; Get["/clients/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedClient = Clients.Find(parameters.id); var selectedStylist = Stylists.Find(selectedClient.GetStylistId()); model.Add("stylist", selectedStylist); model.Add("client", selectedClient); return(View["client.cshtml", model]); }; Get["/stylists/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedStylist = Stylists.Find(parameters.id); var ClientStylist = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", ClientStylist); return(View["stylist.cshtml", model]); }; Post["/stylists/cleared"] = _ => { Clients.DeleteAll(); Stylists.DeleteAll(); return(View["cleared.cshtml"]); }; Post["/clients/cleared"] = _ => { Clients.DeleteAll(); return(View["cleared.cshtml"]); }; Get["/stylists/edit/{id}"] = parameters => { Stylists SelectedStylist = Stylists.Find(parameters.id); return(View["stylist_edit.cshtml", SelectedStylist]); }; Patch["/stylists/edit/{id}"] = parameters => { Stylists SelectedStylists = Stylists.Find(parameters.id); SelectedStylists.Update(Request.Form["name"]); return(View["success.cshtml"]); }; Get["/clients/edit/{id}"] = parameters => { Clients selectedClient = Clients.Find(parameters.id); return(View["client_edit.cshtml", selectedClient]); }; Patch["/clients/edit/{id}"] = parameters => { Clients SelectedClient = Clients.Find(parameters.id); SelectedClient.Update(Request.Form["name"]); return(View["success.cshtml"]); }; Get["stylists/delete/{id}"] = parameters => { Stylists SelectedStylist = Stylists.Find(parameters.id); return(View["stylist_delete.cshtml", SelectedStylist]); }; Delete["stylists/delete/{id}"] = parameters => { Stylists SelectedStylist = Stylists.Find(parameters.id); SelectedStylist.Delete(); return(View["success.cshtml"]); }; Get["clients/delete/{id}"] = parameters => { Clients SelectedClient = Clients.Find(parameters.id); return(View["client_delete.cshtml", SelectedClient]); }; Delete["clients/delete/{id}"] = parameters => { Clients SelectedClient = Clients.Find(parameters.id); SelectedClient.Delete(); return(View["success.cshtml"]); }; }