Esempio n. 1
0
        //find client method/function
        public static Client Find(int id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE id = @ClientId;", conn);
              SqlParameter stylistIdParameter = new SqlParameter();
              stylistIdParameter.ParameterName = "@ClientId";
              stylistIdParameter.Value = id.ToString();
              cmd.Parameters.Add(stylistIdParameter);
              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;
        }
Esempio n. 2
0
        public void Test2_Equal_ReturnsTrueIfNameAreTheSame()
        {
            Client firstClient = new Client("Amy",1);
              Client secondClient = new Client("Amy",1);

              Assert.Equal(firstClient, secondClient);
        }
Esempio n. 3
0
        public void Test5_Find_FindClientInDatabase()
        {
            Client testClient = new Client("Robert",1);
              testClient.Save();

              Client foundClient = Client.Find(testClient.GetId());

              Assert.Equal(testClient, foundClient);
        }
Esempio n. 4
0
        public void Test_Save_Find_FoundItemEqualsItem()
        {
            //Arrange/Act
              Client item = new Client("Janet", 0, "She's a handful.");
              item.Save();

              //Assert
              Assert.Equal(Client.Find(item.id), item);
        }
Esempio n. 5
0
        public void Test_Update()
        {
            //Arrange/Act
              Client item = new Client("Janet", 0, "She's a handful.");
              item.Save();
              item.Update(new List<string>{"name"}, new List<object>{"Sherry"});

              //Assert
              Assert.Equal(item.name, "Sherry");
        }
Esempio n. 6
0
        public void Test_Save_CanRetrieveOneItem()
        {
            //Arrange/Act
              Client item = new Client("Janet", 0, "She's a handful.");
              item.Save();
              List<Client> allClients = Client.GetAll();

              //Assert
              Assert.Equal(1, allClients.Count);
        }
Esempio n. 7
0
        public void Test_Delete()
        {
            //Arrange/Act
              Client item = new Client("Janet", 0, "She's a handful.");
              item.Save();
              item.Delete();

              //Assert
              Assert.Equal(Client.Find(item.id), null);
        }
Esempio n. 8
0
        public void Test3_Save_AssignsIdToObject()
        {
            Client testClient = new Client("Alex",1);

              testClient.Save();
              Client savedClient = Client.GetAll()[0];

              int result = savedClient.GetId();
              int testId = testClient.GetId();

              Assert.Equal(testId, result);
        }
Esempio n. 9
0
        public void Test_GetClients()
        {
            //Arrange
              Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her.");
              item.Save();
              Client a = new Client("Janet", item.id, "She's a handful.");
              a.Save();

              //Act
              List<Client> clients = item.GetClients();

              //Assert
              Assert.Equal(clients[0], a);
        }
Esempio n. 10
0
        public Homemodule()
        {
            Get["/"] = _ => {
            List<Stylist> AllStylists = Stylist.GetAll();
            return View["index.cshtml", AllStylists];
              };

              Get["/clients"] = _ => {
            List<Client> AllClients = Client.GetAll();
            return View["clients.cshtml", AllClients];
              };

              Get["/stylists"] = _ => {
            List<Stylist> AllStylists = Stylist.GetAll();
            return View["stylists.cshtml", AllStylists];
              };

              Get["/stylists/new"] = _ => {
            return View["stylists_form.cshtml"];
              };

              Post["/stylists/new"] = _ => {
            Stylist newStylist = new Stylist(Request.Form["stylist-name"]);
            newStylist.Save();
            return View["success.cshtml"];
              };

              Get["/clients/new"] = _ => {
            List<Stylist> AllStylists = Stylist.GetAll();
            return View["clients_form.cshtml", AllStylists];
              };
              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["/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 => {
            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"];
              };
        }
Esempio n. 11
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 clientName = rdr.GetString(1);
              int clientStylistId = rdr.GetInt32(2);
              Client newClient = new Client(clientName, clientStylistId, clientId);
              clients.Add(newClient);
            }
            if (rdr != null)
            {
              rdr.Close();
            }
            if (conn != null)
            {
              conn.Close();
            }
            return clients;
        }
Esempio n. 12
0
        public static Client Find(int findId)
        {
            DBObjects dbo = DBObjects.CreateCommand("SELECT * FROM clients WHERE id=@Id;", new List<string> {"@Id"},  new List<object> {findId});
              SqlDataReader rdr = dbo.RDR;
              rdr = dbo.CMD.ExecuteReader();

              Client result = null;
              while(rdr.Read())
              {
            result = new Client(rdr.GetString(1), rdr.GetInt32(2), rdr.GetString(3), rdr.GetInt32(0));
              }

              dbo.Close();
              return result;
        }
Esempio n. 13
0
 public HomeModule()
 {
     Get["/"] = _ => {
     List<Stylist> stylists = Stylist.GetAll();
     return View["index.cshtml", stylists];
       };
       Post["/stylists/new"] = _ => {
     Stylist newStylist = new Stylist(Request.Form["name"], Request.Form["avail"], Request.Form["notes"]);
     newStylist.Save();
     List<Stylist> stylists = Stylist.GetAll();
     return View["index.cshtml", stylists];
       };
       Get["/stylists/{id}"] = parameter => {
     Stylist foundStylist = Stylist.Find(parameter.id);
     return View["stylist.cshtml", foundStylist];
       };
       Patch["/stylists/edit/{id}"] = parameter => {
     Stylist editedStylist = Stylist.Find(parameter.id);
     List<string> updateColumns = new List<string> {"name", "availability", "notes"};
     string newStylistId = (string)Request.Form["avail"];
     string newName = (string)Request.Form["name"];
     string newNotes = (string)Request.Form["notes"];
     List<object> updateValues = new List<object> {newName, newStylistId, newNotes};
     editedStylist.Update(updateColumns, updateValues);
     return View["stylist.cshtml", editedStylist];
       };
       Delete["/stylists/delete/{id}"] = parameter => {
     Stylist deletedStylist = Stylist.Find(parameter.id);
     deletedStylist.Delete();
     List<Stylist> stylists = Stylist.GetAll();
     return View["index.cshtml", stylists];
       };
       Post["/clients/new"] = _ => {
     string newName = (string)Request.Form["name"];
     int stylistId = (int)Request.Form["stylist_id"];
     string newNotes = (string)Request.Form["notes"];
     Client newClient = new Client(newName, stylistId, newNotes);
     newClient.Save();
     Stylist foundStylist = Stylist.Find(stylistId);
     return View["stylist.cshtml", foundStylist];
       };
       Get["/clients/{id}"] = parameter => {
     Client foundClient = Client.Find(parameter.id);
     List<object> model = new List<object> {};
     model.Add(foundClient);
     model.Add(Stylist.GetAll());
     return View["client.cshtml", model];
       };
       Patch["/clients/edit/{id}"] = parameter => {
     Client editedClient = Client.Find(parameter.id);
     List<string> updateColumns = new List<string> {"name", "stylist_id", "notes"};
     int newStylistId = (int)Request.Form["stylist_id"];
     string newName = (string)Request.Form["name"];
     string newNotes = (string)Request.Form["notes"];
     List<object> updateValues = new List<object> {newName, newStylistId, newNotes};
     editedClient.Update(updateColumns, updateValues);
     List<object> model = new List<object> {};
     model.Add(editedClient);
     model.Add(Stylist.GetAll());
     return View["client.cshtml", model];
       };
       Delete["/clients/delete/{id}"] = parameter => {
     Client deletedClient = Client.Find(parameter.id);
     deletedClient.Delete();
     Stylist foundStylist = Stylist.Find(deletedClient.stylist_id);
     return View["stylist.cshtml", foundStylist];
       };
 }
Esempio n. 14
0
        //get all mehtod/function
        public static List<Client> GetAll()
        {
            List<Client> allClients = 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);
            allClients.Add(newClient);
              }

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }

              return allClients;
        }