Beispiel #1
0
        public static Client Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE id = @ClientId;", conn);
              SqlParameter clientIdParameter = new SqlParameter();
              clientIdParameter.ParameterName = "@ClientId";
              clientIdParameter.Value = id.ToString();
              cmd.Parameters.Add(clientIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              int foundClientId = 0;
              string foundClientName = null;
              int foundClientStylistId = 0;

              while(rdr.Read())
              {
            foundClientId = rdr.GetInt32(0);
            foundClientName = rdr.GetString(1);
            foundClientStylistId = rdr.GetInt32(2);
              }
              Client foundClient = new Client(foundClientName, foundClientStylistId, foundClientId);

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundClient;
        }
Beispiel #2
0
 public void T2_Equal_ReturnsTrueIfNamesAreTheSame()
 {
     //arrange, act
       Client firstClient = new Client("Jill", 1);
       Client secondClient = new Client("Jill", 1);
       //Assert
       Assert.Equal(firstClient, secondClient);
 }
Beispiel #3
0
 public void T5_Find_FindNameInDatabase()
 {
     //arrange
       Client testClient = new Client("Jill", 1);
       testClient.Save();
       //act
       Client foundClient = Client.Find(testClient.GetId());
       //Assert
       Assert.Equal(testClient, foundClient);
 }
Beispiel #4
0
 public void T3_Test_Save_SavesToDatabase()
 {
     //arrange
       Client testList = new Client("Jill", 1);
       //act
       testList.Save();
       List<Client> result = Client.GetAll();
       List<Client> testClient = new List<Client>{testList};
       //Assert
       Assert.Equal(testClient, result);
 }
Beispiel #5
0
        public void T4_Save_AssignsIdToObject()
        {
            //arrange
              Client testClient = new Client("Jill", 1);
              //act
              testClient.Save();
              Client savedClient = Client.GetAll()[0];

              int result = savedClient.GetId();
              int testId = testClient.GetId();
              //Assert
              Assert.Equal(testId, result);
        }
Beispiel #6
0
        public static List<Client> GetAll()
        {
            List<Client> allClient = new List<Client>{};

              SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM clients;", conn);
              SqlDataReader rdr = cmd.ExecuteReader();

              while (rdr.Read())
              {
            int clientId = rdr.GetInt32(0);
            string clientName = rdr.GetString(1);
            int clientStylistId = rdr.GetInt32(2);
            Client newClient = new Client(clientName, clientStylistId, clientId);
            allClient.Add(newClient);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allClient;
        }
Beispiel #7
0
 public HomeModule()
 {
     Get ["/"] = _ => {
     List<Stylist> AllStylist = Stylist.GetAll();
     return View["index.cshtml", AllStylist];
       };
       Get["/clients"] = _ => {
     List<Client> AllClients = Client.GetAll();
     return View["clients.cshtml", AllClients];
       };
       Get["/stylist"] = _ => {
     List<Stylist> AllStylist = Stylist.GetAll();
     return View["stylists.cshtml", AllStylist];
       };
       Get["/stylist/new"] = _ => {
     return View["stylists_form.cshtml"];
       };
       Post["/stylist/new"] = _ =>{
     Stylist newStylist = new Stylist(Request.Form["stylist-name"]);
     newStylist.Save();
     return View["success.cshtml"];
       };
       Get["/clients/new"] = _ => {
     List<Stylist> AllStylist = Stylist.GetAll();
     return View["clients_form.cshtml", AllStylist];
       };
       Post["/clients/new"] = _ => {
     Client newClient = new Client(Request.Form["client-name"], Request.Form["stylist-id"]);
     newClient.Save();
     return View["success.cshtml"];
       };
       Post["/clients/delete"] = _ => {
     Client.DeleteAll();
     return View["cleared.cshtml"];
       };
       Get["/stylist/{id}"] = parameters => {
     Dictionary<string, object> model = new Dictionary<string, object>();
     var SelectedStylist = Stylist.Find(parameters.id);
     var StylistClients = SelectedStylist.GetClients();
     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"];
       };
       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"];
       };
 }
Beispiel #8
0
        public List<Client> GetClients()
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE stylist_id = @StylistId;", conn);
              SqlParameter stylistIdParameter = new SqlParameter();
              stylistIdParameter.ParameterName = "@StylistId";
              stylistIdParameter.Value = this.GetId();
              cmd.Parameters.Add(stylistIdParameter);
              SqlDataReader rdr = cmd.ExecuteReader();

              List<Client> clients = new List<Client> {};
              while(rdr.Read())
              {
            int clientId = rdr.GetInt32(0);
            string clientDescription = rdr.GetString(1);
            int clientStylistId = rdr.GetInt32(2);
            Client newClient = new Client(clientDescription, clientStylistId, clientId);
            clients.Add(newClient);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return clients;
        }
Beispiel #9
0
        public void T6_GetClients_RetrievesAllClientsWithStylist()
        {
            Stylist testStylist = new Stylist("Jane");
              testStylist.Save();

              Client firstClient = new Client("Jill", testStylist.GetId());
              firstClient.Save();
              Client secondClient = new Client("Lisa", testStylist.GetId());
              secondClient.Save();

              List<Client> testClientList = new List<Client> {firstClient, secondClient};
              List<Client> resultClientList = testStylist.GetClients();

              Assert.Equal(testClientList, resultClientList);
        }
Beispiel #10
0
        public void T8_Delete_DeletesStylistFromDatabase()
        {
            //Arrange
              string name1 = "Mike";
              Stylist testStylist1 = new Stylist(name1);
              testStylist1.Save();

              string name2 = "Lucy";
              Stylist testStylist2 = new Stylist(name2);
              testStylist2.Save();

              Client testClient1 = new Client("Shirley", testStylist1.GetId());
              testClient1.Save();
              Client testClient2 = new Client("Bob", testStylist2.GetId());
              testClient2.Save();

              //Act
              testStylist1.Delete();
              List<Stylist> resultStylist = 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, resultStylist);
              Assert.Equal(testClientList, resultClients);
        }