public static Stylist Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM stylists WHERE id = @StylistId;", conn); SqlParameter stylistIdParameter = new SqlParameter(); stylistIdParameter.ParameterName = "@StylistId"; stylistIdParameter.Value = id.ToString(); cmd.Parameters.Add(stylistIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundStylistId = 0; string foundStylistName = null; while(rdr.Read()) { foundStylistId = rdr.GetInt32(0); foundStylistName = rdr.GetString(1); } Stylist foundStylist = new Stylist(foundStylistName,foundStylistId); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return foundStylist; }
public static List<Stylist> GetAll() { List<Stylist> allStylists = new List<Stylist>{}; 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); Stylist newStylist = new Stylist(stylistName,stylistId); allStylists.Add(newStylist); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return allStylists; }
public void Test1_Stylist_Equal_returnTrue() { //Arrange, Act Stylist myStylist= new Stylist("wer",5); Stylist myOtherStylist= new Stylist("wer",5); //Assert Assert.Equal(myStylist, myOtherStylist); }
public void Test4_FindId() { Stylist myStylist = new Stylist("kjoio",2); myStylist.Save(); Stylist findStylist = Stylist.Find(myStylist.GetId()); Assert.Equal(findStylist, myStylist); }
public HomeModule() { Get["/"] = _ => { var allStylists = Stylist.GetAll(); return View["index.cshtml", allStylists]; }; Post["/"] = _ => { var newStylist = new Stylist(Request.Form["stylist-name"], Request.Form["stylist-specialty"]); newStylist.Save(); var allStylists = Stylist.GetAll(); return View["index.cshtml", allStylists]; }; Get["/stylists/{id}"] = parameters => { Dictionary<string, object> model = new Dictionary<string, object>(); var selectedStylist = Stylist.Find(parameters.id); var stylistClients = selectedStylist.GetClients(parameters.id); model.Add("stylist", selectedStylist); model.Add("clients", stylistClients); return View["stylist.cshtml", model]; }; Get["/stylist/edit/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); return View["stylist_edit.cshtml", selectedStylist]; }; Patch["stylist/edit/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); selectedStylist.Update(Request.Form["stylist-name"]); return View["success.cshtml"]; }; Post["/stylist/new"] = _ => { Client newClient = new Client(Request.Form["client-name"], Request.Form["client-treatment"], Request.Form["stylist-id"]); newClient.Save(); return View["success.cshtml"]; }; Get["stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); return View["stylist_delete.cshtml", SelectedStylist]; }; Delete["stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Delete(); return View["success.cshtml"]; }; }
public void Test_Save_SavesToDatabase() { // Arrange Stylist testStylist = new Stylist("Doc Gonzo", "Brush"); testStylist.Save(); // Act List<Stylist> listResult = Stylist.GetAll(); List<Stylist> listExpected = new List<Stylist>{testStylist}; // Assert Assert.Equal(listExpected, listResult); }
public void Test_Save_AssignsIdToObject() { // Arrange Stylist testStylist = new Stylist("Doc Gonzo", "Haircut"); // Act testStylist.Save(); Stylist savedStylist = Stylist.GetAll()[0]; int result = savedStylist.GetId(); int testId = testStylist.GetId(); // Assert Assert.Equal(testId, result); }
public void Test2_Save_Stylist_true() { //Arrange, Act Stylist myStylist= new Stylist("wer"); myStylist.Save(); //Act List<Stylist> result = Stylist.GetAll(); List<Stylist> testList = new List<Stylist>{myStylist}; //Assert Assert.Equal(testList, result); }
public void Test3_Save_ID_true() { Stylist myStylist = new Stylist ("sdojofdkoedf"); myStylist.Save(); //List return list of Stylist List<Stylist> allStylist= Stylist.GetAll(); Stylist oneStylist = allStylist[0]; int resultId= oneStylist.GetId(); int testId=myStylist.GetId(); Assert.Equal(resultId, testId); }
public void Test5_GetAllClient_esInStylist_true() { Stylist myStylist = new Stylist("lo-main"); myStylist.Save(); Client firstClient = new Client("Pizza",myStylist.GetId()); firstClient.Save(); Client secondClient = new Client("tacos",myStylist.GetId()); secondClient.Save(); List<Client> testClientList = new List<Client> {firstClient,secondClient}; List<Client> resultClientList = myStylist.GetClient(); Assert.Equal(testClientList, resultClientList); }
public void Test_Delete_DeletesStylistFromDatabase() { // Arrange string name = "Doctor Gonzo"; Stylist testStylist = new Stylist(name, "Cuts"); testStylist.Save(); string name2 = "Mouse"; Stylist testStylist2 = new Stylist(name2, "Brushes"); testStylist2.Save(); Client testClient = new Client("Sid", "Cut", testStylist.GetId()); testClient.Save(); Client testClient2 = new Client("Yousef", "Color", testStylist2.GetId()); testClient2.Save(); // Act testStylist.Delete(); List<Stylist> resultStylists = Stylist.GetAll(); List<Stylist> testStylistList = new List<Stylist> {testStylist2}; List<Client> resultClients = Client.GetAll(); List<Client> testClientList = new List<Client> {testClient2}; // Assert Assert.Equal(testStylistList, resultStylists); Assert.Equal(testClientList, resultClients); }
public HomeModule() { Get["/"] = _ => { List <Stylist> AllStylist = Stylist.GetAll(); return(View["index.cshtml", AllStylist]); }; Get["/clients"] = _ => { List <Client> AllClient = Client.GetAll(); return(View["clients.cshtml", AllClient]); }; Get["/stylists"] = _ => { List <Stylist> AllStylist = Stylist.GetAll(); return(View["stylists.cshtml", AllStylist]); }; Get["/stylists/new"] = _ => { return(View["stylists_form.cshtml"]); }; Post["stylists/new"] = _ => { Stylist newStylist = new Stylist(Request.Form["stylist-name"]); List <Stylist> AllStylist = Stylist.GetAll(); newStylist.Save(); return(View["success.cshtml", AllStylist]); }; Get["/clients/new"] = _ => { List <Stylist> AllClient = Stylist.GetAll(); return(View["clients_form.cshtml", AllClient]); }; Post["/clients/new"] = _ => { Client newClient = new Client(Request.Form["client-name"], Request.Form["stylist-id"]); List <Client> AllClient = Client.GetAll(); newClient.Save(); return(View["clients.cshtml", AllClient]); }; Post["/clients/clear"] = _ => { Client.DeleteAll(); return(View["cleared.cshtml"]); }; Get["/clients/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var SelectedStylist = Stylist.Find(parameters.id); var StylistClients = SelectedStylist.GetClients(); model.Add("stylist", SelectedStylist); model.Add("clients", StylistClients); return(View["clients.cshtml", model]); }; Get["/client/edit/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Stylist SelectedStylist = Stylist.Find(parameters.id); List <Client> StylistClients = SelectedStylist.GetClients(); model.Add("client", SelectedStylist); model.Add("clients", StylistClients); return(View["client_edit.cshtml", model]); }; Patch["/client/edit/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Update(Request.Form["client-name"]); return(View["success.cshtml"]); }; Get["/client/delete/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Client SelectedClient = Client.Find(parameters.id); model.Add("client", SelectedClient); return(View["client_delete.cshtml", model]); }; Delete["/client/delete/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Client SelectedClient = Client.Find(parameters.id); SelectedClient.Delete(); return(View["success.cshtml"]); }; Get["/stylists/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var SelectedStylist = Stylist.Find(parameters.id); var StylistClients = SelectedStylist.GetClients(); model.Add("stylist", SelectedStylist); model.Add("clients", StylistClients); return(View["stylist.cshtml", model]); }; Get["/stylist/edit/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Stylist SelectedStylist = Stylist.Find(parameters.id); List <Client> StylistClients = SelectedStylist.GetClients(); model.Add("stylist", SelectedStylist); model.Add("clients", StylistClients); return(View["stylist_edit.cshtml", model]); }; Patch["/stylist/edit/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Update(Request.Form["stylist-name"]); return(View["success.cshtml"]); }; Get["/stylist/delete/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Stylist SelectedStylist = Stylist.Find(parameters.id); List <Client> StylistClients = SelectedStylist.GetClients(); model.Add("stylist", SelectedStylist); model.Add("clients", StylistClients); return(View["stylist_delete.cshtml", model]); }; Delete["/stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Delete(); return(View["success.cshtml"]); }; }
public void Test7_Delete_OneStylist_true() { Stylist firstStylist = new Stylist("A"); firstStylist.Save(); Stylist secondStylist = new Stylist("B"); secondStylist.Save(); Client firstStylistClient = new Client("sddsds",firstStylist.GetId()); firstStylistClient.Save(); Client secondStylistDsih= new Client("dssdsdds",secondStylist.GetId()); secondStylistDsih.Save(); firstStylist.Delete(); List<Stylist> allStylists = Stylist.GetAll(); List<Stylist> afterDeleteOneStylist= new List<Stylist> {secondStylist}; List<Client> resultClient=Client.GetAll(); List<Client> afterDeleteOneStylistClient= new List<Client> {secondStylistDsih}; Assert.Equal(afterDeleteOneStylist,allStylists); Assert.Equal(afterDeleteOneStylistClient,resultClient); }
public void Dispose() { Client.DeleteAll(); Stylist.DeleteAll(); }
public HomeModule() { Get["/"] = _ => { List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; Post["/stylist/new"] = _ => { Stylist newStylist = new Stylist(Request.Form["new-stylist-first"], Request.Form["new-stylist-last"], Request.Form["new-stylist-expertise"]); newStylist.Save(); List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; Post["/clients/{id}"] = parameters => { Client newClient = new Client(Request.Form["new-client-first"], Request.Form["new-client-last"], Request.Form["new-client-stylist-id"]); newClient.Save(); Dictionary <string, object> model = new Dictionary <string, object>(); Stylist selectedStylist = Stylist.Find(parameters.id); List <Client> stylistClients = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", stylistClients); return(View["clients.cshtml", model]); }; Get["/clients/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Stylist selectedStylist = Stylist.Find(parameters.id); List <Client> stylistClients = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", stylistClients); return(View["clients.cshtml", model]); }; Get["/stylist/edit/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); return(View["stylist_edit.cshtml", selectedStylist]); }; Patch["/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); selectedStylist.Update(Request.Form["update-stylist-expertise"]); List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; Delete["/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); selectedStylist.DeleteStylistClients(); selectedStylist.Delete(); List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; Get["/client/edit/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); List <Stylist> allStylists = Stylist.GetAll(); Client currentClient = Client.Find(parameters.id); Stylist currentStylist = Stylist.Find(currentClient.GetStylistId()); model.Add("stylists", allStylists); model.Add("client", currentClient); model.Add("stylist", currentStylist); return(View["client_edit.cshtml", model]); }; Patch["/clients/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Client selectedClient = Client.Find(parameters.id); selectedClient.Update(Request.Form["update-client-first"], Request.Form["update-client-last"], Request.Form["update-client-stylist-id"]); Stylist selectedStylist = Stylist.Find(selectedClient.GetStylistId()); List <Client> stylistClients = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", stylistClients); return(View["clients.cshtml", model]); }; Delete["/clients/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Client selectedClient = Client.Find(parameters.id); Stylist selectedStylist = Stylist.Find(selectedClient.GetStylistId()); selectedClient.Delete(); List <Client> stylistClients = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", stylistClients); return(View["clients.cshtml", model]); }; }
public void T1_DBEmptyAtFirst() { int result = Stylist.GetAll().Count; Assert.Equal(0, result); }
public void Dispose() { Stylist.DeleteAll(); }
public void Test6_Update_StylistInDatabase() { Stylist myStylist = new Stylist("befewfefwrg"); myStylist.Save(); myStylist.Update("er"); string result = myStylist.GetName(); Assert.Equal("er", result); }
public HomeModule() { Get["/"] = _ => { List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; Get["/clients/{id}"] = parameters => { List <Client> allClients = Client.GetAll(parameters.id); return(View["clients.cshtml", allClients]); }; Get["/client/{id}"] = parameters => { Client foundClient = Client.Find(parameters.id); return(View["client.cshtml", foundClient]); }; Get["/clients/add/{id}"] = parameters => { int model = parameters.id; return(View["add-client.cshtml", model]); }; Get["/stylist/update/{id}"] = parameters => { Stylist model = Stylist.Find(parameters.id); return(View["update-stylist.cshtml", model]); }; Get["/client/update/{id}"] = parameters => { Client model = Client.Find(parameters.id); return(View["update-client.cshtml", model]); }; Post["/stylist/delete/{id}"] = parameters => { Stylist newStylist = Stylist.Find(parameters.id); string name = newStylist.GetName(); Stylist.RemoveAStylist(parameters.id); return(View["stylist-deleted.cshtml", name]); }; Post["/client/delete/{id}"] = parameters => { Client newClient = Client.Find(parameters.id); string name = newClient.GetName(); Client.RemoveAClient(parameters.id); return(View["client-deleted.cshtml", name]); }; Post["/stylist-added"] = _ => { string name = Request.Form["name"]; string hours = Request.Form["hours"]; int phone = Request.Form["phone"]; Stylist newStylist = new Stylist(name, hours, phone); newStylist.Save(); return(View["stylist-added.cshtml", newStylist]); }; Post["/client-added/{id}"] = parameters => { string name = Request.Form["name"]; string hair_color = Request.Form["hair"]; int phone = Request.Form["phone"]; Client newClient = new Client(name, hair_color, phone, parameters.id); newClient.Save(); return(View["client-added.cshtml", newClient]); }; Post["/client-updated/{id}"] = parameters => { string name = Request.Form["name"]; string hair_color = Request.Form["hair"]; int phone = Request.Form["phone"]; Client.Update(name, hair_color, phone, parameters.id); List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; Post["/stylist-updated/{id}"] = parameters => { string name = Request.Form["name"]; string hours = Request.Form["hours"]; int phone = Request.Form["phone"]; Stylist.Update(name, hours, phone, parameters.id); List <Stylist> allStylists = Stylist.GetAll(); return(View["index.cshtml", allStylists]); }; }
public void Test_DatabaseEmptyAtFirst() { int result = Stylist.GetAll().Count; Assert.Equal(0, result); }
public void Test_Updated_UpdatesStylistInDatabase() { // Arrange string name = "Doctor Gonzo"; Stylist testStylist = new Stylist(name, "Cuts"); testStylist.Save(); string newName = "Dr. Gonzo"; // Act testStylist.Update(newName); string result = testStylist.GetName(); // Assert Assert.Equal(newName, result); }
public HomeModule() { Get["/"] = _ => { Dictionary<string,object> model=Member.AllData("Welcome To Our Salon!"); return View["index.cshtml",model]; }; Post["/stylist/new"] =_ => { Stylist newStylist = new Stylist(Request.Form["new-name"]); newStylist.Save(); string message="Thank you for join us "+Request.Form["new-name"]; Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Post["/client/new"] =_ => { Client newClient = new Client(Request.Form["new-name"],Request.Form["stylist-id"]); newClient.Save(); string message="We appreciated your bussiness. "+Request.Form["new-name"]; Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Delete["/delete/stylist/{id}"]=parameters =>{ Stylist foundStylist = Stylist.Find(parameters.id); string message="You Suscessfully Delete "+foundStylist.GetName(); foundStylist.Delete(); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Patch["/edit/stylist/{id}"]=parameters =>{ Stylist foundStylist = Stylist.Find(parameters.id); string message="You Suscessfully Change Name from"+ foundStylist.GetName()+" to "+ Request.Form["edit-stylist-name"]; foundStylist.Update(Request.Form["edit-stylist-name"]); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Delete["/delete/client/{id}"]=parameters =>{ Client foundClient = Client.Find(parameters.id); string message="You Suscessfully Delete "+foundClient.GetName(); foundClient.Delete(); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Patch["/edit/client/{id}"]=parameters =>{ Client foundClient = Client.Find(parameters.id); string message="You Suscessfully Change Name from"+ foundClient.GetName()+" to "+ Request.Form["edit-client-name"]; foundClient.Update(Request.Form["edit-client-name"]); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Get["/Client/{id}"]=parameters =>{ Stylist foundStylist = Stylist.Find(parameters.id); List<Client> allMyClients=foundStylist.GetClient(); Dictionary<string,object> model= new Dictionary<string,object>{}; model.Add("stylist",foundStylist); model.Add("client",allMyClients); return View["client.cshtml",model]; }; Get["/delete-all"]=_=>{ return View["confirmation.cshtml"]; }; Post["/delete/confirmation"]=_=>{ string message=" You enter wrong password, and thus you cannont delete anything."; if(Request.Form["confirm-delete"]=="delete-all-clients"&&Request.Form["user-password"]=="123") { Client.DeleteAll(); message=Request.Form["userName"]+", You deleted all client data"; }else if(Request.Form["confirm-delete"]=="delete-all"&&Request.Form["user-password"]=="123") { message=Request.Form["userName"]+", You deleted all data"; Client.DeleteAll(); Stylist.DeleteAll(); } Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; }