Ejemplo n.º 1
0
        public void Test2_Equal_ReturnsTrueIfNameAreTheSame()
        {
            Stylist firstStylist = new Stylist("Bobby");
              Stylist secondStylist = new Stylist("Bobby");

              Assert.Equal(firstStylist, secondStylist);
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        public void Test5_Find_NewStylistInDatabase()
        {
            Stylist testStylist = new Stylist ("Maggy");
              testStylist.Save();

              Stylist foundStylist = Stylist.Find(testStylist.GetId());

              Assert.Equal(testStylist, foundStylist);
        }
Ejemplo n.º 4
0
        public void Test_Save_Find_FoundItemEqualsItem()
        {
            //Arrange/Act
              Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her.");
              item.Save();

              //Assert
              Assert.Equal(Stylist.Find(item.id), item);
        }
Ejemplo n.º 5
0
        public void Test3_SavesToDatabase()
        {
            Stylist testStylist = new Stylist("Jimmy");

              testStylist.Save();
              List<Stylist> result = Stylist.GetAll();
              List<Stylist> testList = new List<Stylist>{testStylist};

              Assert.Equal(testList, result);
        }
Ejemplo n.º 6
0
        public void Test_Delete()
        {
            //Arrange/Act
              Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her.");
              item.Save();
              item.Delete();

              //Assert
              Assert.Equal(Stylist.Find(item.id), null);
        }
Ejemplo n.º 7
0
        public void Test_Save_CanRetrieveOneItem()
        {
            //Arrange/Act
              Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her.");
              item.Save();
              List<Stylist> allStylists = Stylist.GetAll();

              //Assert
              Assert.Equal(1, allStylists.Count);
        }
Ejemplo n.º 8
0
        public void Test4_Save_AssignIdToObject()
        {
            Stylist testStylist = new Stylist("Anthony");

              testStylist.Save();
              Stylist savedStylist = Stylist.GetAll()[0];

              int result = savedStylist.GetId();
              int testId = testStylist.GetId();

              Assert.Equal(testId, result);
        }
Ejemplo n.º 9
0
        public void Test6_Update_StylistToDatabase()
        {
            string name = "Maggy";
              Stylist testStylist = new Stylist(name);
              testStylist.Save();
              string newName = "Steve";

              testStylist.Update(newName);

              string result = testStylist.GetName();

              Assert.Equal(newName, result);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        public void Test_Update()
        {
            //Arrange/Act
              Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her.");
              item.Save();
              item.Update(new List<string>{"name"}, new List<object>{"Sherry"});

              //Assert
              Assert.Equal(Stylist.Find(item.id).name, "Sherry");
        }
Ejemplo n.º 12
0
        public void Test_DatabaseEmptyAtFirst()
        {
            int result = Stylist.GetAll().Count;

            Assert.Equal(0, result);
        }
Ejemplo n.º 13
0
 public void Dispose()
 {
     Stylist.DeleteAll();
 }
Ejemplo n.º 14
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     //CREATE
     Get["/client/new"] = _ => {
         List <Stylist> AllStylists = Stylist.GetAll();
         return(View["add_client.cshtml", AllStylists]);
     };
     Get["/stylist/new"] = _ => {
         return(View["add_stylist.cshtml"]);
     };
     Post["/clients"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Client newClient       = new Client(Request.Form["client-name"], Request.Form["client-phone"], Request.Form["client-email"], Request.Form["stylist"]);
         var    selectedStylist = Stylist.Find(newClient.GetStylistId());
         newClient.Save();
         model.Add("stylist", selectedStylist);
         model.Add("client", newClient);
         return(View["success.cshtml", model]);
     };
     Post["/stylists"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Stylist newStylist      = new Stylist(Request.Form["stylist-name"], Request.Form["stylist-phone"], Request.Form["stylist-email"]);
         var     selectedStylist = Stylist.Find(newStylist.GetId());
         newStylist.Save();
         model.Add("stylist", newStylist);
         return(View["success.cshtml", newStylist]);
     };
     //READ
     Get["/clients"] = _ => {
         List <Client> AllClients = Client.GetAll();
         return(View["clients.cshtml", AllClients]);
     };
     Get["/stylists"] = _ => {
         List <Stylist> AllStylist = Stylist.GetAll();
         return(View["stylists.cshtml", AllStylist]);
     };
     Get["/clients/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var selectedClient  = Client.Find(parameters.id);
         var selectedStylist = Stylist.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 = Stylist.Find(parameters.id);
         var ClientsStylist  = selectedStylist.GetClients();
         model.Add("stylist", selectedStylist);
         model.Add("clients", ClientsStylist);
         return(View["stylist.cshtml", model]);
     };
     //UPDATE
     Get["/client/edit/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object> {
         };
         Client         SelectedClient     = Client.Find(parameters.id);
         List <Stylist> AllStylists        = Stylist.GetAll();
         model.Add("client", SelectedClient);
         model.Add("stylists", Stylist.GetAll());
         return(View["edit_client.cshtml", model]);
     };
     Get["/stylist/edit/{id}"] = parameters => {
         Stylist SelectedStylist = Stylist.Find(parameters.id);
         return(View["edit_stylist.cshtml", SelectedStylist]);
     };
     Patch["/client/edit/{id}"] = parameters => {
         Client SelectedClient  = Client.Find(parameters.id);
         var    selectedStylist = Stylist.Find(SelectedClient.GetStylistId());
         SelectedClient.Update(Request.Form["client-name"], Request.Form["client-phone"], Request.Form["client-email"], Request.Form["stylist-id"]);
         return(View["success.cshtml"]);
     };
     Patch["/stylist/edit/{id}"] = parameters => {
         Stylist SelectedStylist = Stylist.Find(parameters.id);
         SelectedStylist.Update(Request.Form["stylist-name"], Request.Form["stylist-phone"], Request.Form["stylist-email"]);
         return(View["success.cshtml"]);
     };
     //DESTROY
     Get["client/delete/{id}"] = parameters => {
         Client SelectedClient = Client.Find(parameters.id);
         return(View["delete_client.cshtml", SelectedClient]);
     };
     Get["stylist/delete/{id}"] = parameters => {
         Stylist SelectedStylist = Stylist.Find(parameters.id);
         return(View["delete_stylist.cshtml", SelectedStylist]);
     };
     Delete["client/delete/{id}"] = parameters => {
         Client SelectedClient = Client.Find(parameters.id);
         SelectedClient.Delete();
         return(View["success.cshtml"]);
     };
     Delete["stylist/delete/{id}"] = parameters => {
         Stylist SelectedStylist = Stylist.Find(parameters.id);
         SelectedStylist.Delete();
         return(View["success.cshtml"]);
     };
     Post["/clients/cleared"] = _ => {
         Client.DeleteAll();
         return(View["cleared.cshtml"]);
     };
     Post["/stylists/cleared"] = _ => {
         Client.DeleteAll();
         Stylist.DeleteAll();
         return(View["cleared.cshtml"]);
     };
 }
Ejemplo n.º 15
0
        public static List<Stylist> GetAll()
        {
            List<Stylist> allStylists = new List<Stylist>{};

              SqlConnection conn = DB.Connection();
              conn.Open();
              //using parameters: creating sql command
              SqlCommand cmd = new SqlCommand("SELECT * FROM stylists;", conn);
              // no placeholder in the above command : place holder example is @stylists
              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;
        }
Ejemplo n.º 16
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Stylist> AllLists = Stylist.GetAll();
                return(View["index.cshtml"]);
            };
            Get["/stylists"] = _ => {
                var AllStylists = Stylist.GetAll();
                return(View["stylists.cshtml", AllStylists]);
            };
            Get["/clients"] = _ => {
                var AllClients = Client.GetAll();
                return(View ["clients.cshtml", AllClients]);
            };
            Get["/stylists/new"] = _ => {
                return(View["stylists_form.cshtml"]);
            };
            Post["/stylists/new"] = _ => {
                Stylist newStylist = new Stylist(Request.Form["name"], Request.Form["availability"]);
                newStylist.Save();
                List <Stylist> allStylists = Stylist.GetAll();
                return(View["success.cshtml"]);
            };
            Get["/client/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"]);
                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 stylistClientsList = selectedStylist.GetClients();
                model.Add("stylist", selectedStylist);
                model.Add("clients", stylistClientsList);
                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.UpdateName(Request.Form["stylist-name"]);
                return(View["success.cshtml"]);
            };
            Get["/client/edit/{id}"] = parameters => {
                Client selectedClient = Client.Find(parameters.id);
                return(View["client_edit.cshtml", selectedClient]);
            };
            Patch["/client/edit/{id}"] = parameters => {
                Client selectedClient = Client.Find(parameters.id);
                selectedClient.UpdateName(Request.Form["client-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"]);
            };
            Get["/client/delete/{id}"] = parameters => {
                Client selectedClient = Client.Find(parameters.id);
                return(View["/client_delete.cshtml", selectedClient]);
            };
            Delete["/client/delete/{id}"] = parameters => {
                Client selectedClient = Client.Find(parameters.id);
                selectedClient.Delete();
                return(View["success.cshtml"]);
            };
        }
Ejemplo n.º 17
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"]);
            };

            Post["/stylists/delete"] = _ => {
                Stylist.DeleteAll();
                return(View["delete_all.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["delete_all.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["delete_all.cshtml"]);
            };
        }
Ejemplo n.º 18
0
 public void Dispose()
 {
     Client.DeleteAll();
     Stylist.DeleteAll();
 }
Ejemplo n.º 19
0
        public static Stylist Find(int findId)
        {
            DBObjects dbo = DBObjects.CreateCommand("SELECT * FROM stylists WHERE id=@Id;", new List<string> {"@Id"},  new List<object> {findId});
              SqlDataReader rdr = dbo.RDR;
              rdr = dbo.CMD.ExecuteReader();

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

              dbo.Close();
              return result;
        }
Ejemplo n.º 20
0
        public void GetAll_StylistsEmptyAtFirst_0()
        {
            int result = Stylist.GetAll().Count;

            Assert.Equal(0, result);
        }
Ejemplo n.º 21
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];
       };
 }
Ejemplo n.º 22
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"];
              };
        }
Ejemplo n.º 23
0
        public void Test1_EmptyDatabase()
        {
            int result = Stylist.GetAll().Count;

            Assert.Equal(0, result);
        }