Esempio n. 1
0
        public static List <Salon> GetAll()
        {
            List <Salon> allSalons = new List <Salon> {
            };

            SqlConnection conn = DB.Connection();

            conn.Open();

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

            while (rdr.Read())
            {
                int    salonId    = rdr.GetInt32(0);
                string salonName  = rdr.GetString(1);
                string salonAbout = rdr.GetString(2);
                Salon  newSalon   = new Salon(salonName, salonAbout, salonId);
                allSalons.Add(newSalon);
            }
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
            return(allSalons);
        }
Esempio n. 2
0
        public void Test_SalonDatabaseEmptyAtFirst()
        {
            //Arrange, Act
            int result = Salon.GetAll().Count;

            //Assert
            Assert.Equal(0, result);
        }
Esempio n. 3
0
        public void Test_Equal_ReturnsTrueForSameInfo()
        {
            //Arrange, Act
            Salon firstSalon  = new Salon("British Hairways", "a great salon");
            Salon secondSalon = new Salon("British Hairways", "a great salon");

            //Assert
            Assert.Equal(firstSalon, secondSalon);
        }
Esempio n. 4
0
        public void Test_Find_FindsSalonInDatabase()
        {
            //Arrange
            Salon testSalon = new Salon("British Hairways", "a great salon");

            testSalon.Save();
            //Act
            Salon foundSalon = Salon.Find(testSalon.GetId());

            //Assert
            Assert.Equal(testSalon, foundSalon);
        }
Esempio n. 5
0
        public void Test_Update_ReturnsTrueIfSalonInfoIsTheSame()
        {
            //Arrange
            Salon firstTestSalon = new Salon("British Hairways", "a great salon");

            firstTestSalon.Save();
            Salon secondTestSalon = new Salon("The Second Combing", "a wonderful salon", firstTestSalon.GetId());

            //Act
            secondTestSalon.Update("British Hairways", "a great salon");
            //Assert
            Assert.Equal(firstTestSalon, secondTestSalon);
        }
Esempio n. 6
0
        public void Test_Save_AssignsIdToSalonInDatabase()
        {
            //Arrange
            Salon testSalon = new Salon("British Hairways", "a great salon");

            testSalon.Save();
            //Act
            Salon savedSalon = Salon.GetAll()[0];
            int   testId     = testSalon.GetId();
            int   expectedId = savedSalon.GetId();

            //Assert
            Assert.Equal(testId, expectedId);
        }
Esempio n. 7
0
        public void Test_Save_SavesSalonToDatabase()
        {
            //Arrange
            Salon testSalon = new Salon("British Hairways", "a great salon");

            testSalon.Save();
            //Act
            List <Salon> result         = Salon.GetAll();
            List <Salon> expectedResult = new List <Salon> {
                testSalon
            };

            //Assert
            Assert.Equal(result, expectedResult);
        }
Esempio n. 8
0
 public override bool Equals(System.Object otherSalon)
 {
     if (!(otherSalon is Salon))
     {
         return(false);
     }
     else
     {
         Salon newSalon      = (Salon)otherSalon;
         bool  idEquality    = this.GetId() == newSalon.GetId();
         bool  nameEquality  = this.GetName() == newSalon.GetName();
         bool  aboutEquality = this.GetAbout() == newSalon.GetAbout();
         return(idEquality && nameEquality && aboutEquality);
     }
 }
Esempio n. 9
0
        public void Test_Update_ReturnsTrueIfSalonIdsAreTheSame()
        {
            //Arrange
            Salon newSalon = new Salon("British Hairways", "a great salon");

            newSalon.Save();
            Stylist firstTestStylist = new Stylist("Harry Cutter", "a great stylist", newSalon.GetId());

            firstTestStylist.Save();
            Stylist secondTestStylist = new Stylist("Harry Cutter", "a great stylist", 3, firstTestStylist.GetId());

            //Act
            secondTestStylist.Update(firstTestStylist.GetSalonId());
            //Assert
            Assert.Equal(firstTestStylist, secondTestStylist);
        }
Esempio n. 10
0
        public void Test_Update_ReturnsTrueIfStylistInfoIsTheSame()
        {
            //Arrange
            Salon newSalon = new Salon("British Hairways", "a great salon");

            newSalon.Save();
            Stylist firstTestStylist = new Stylist("Harry Cutter", "a great stylist", newSalon.GetId());

            firstTestStylist.Save();
            Stylist secondTestStylist = new Stylist("Dwayne Johnson", "a wonderful stylist", newSalon.GetId(), firstTestStylist.GetId());

            //Act
            secondTestStylist.Update("Harry Cutter", "a great stylist");
            //Assert
            Assert.Equal(firstTestStylist, secondTestStylist);
        }
Esempio n. 11
0
        public void Test_Save_SavesMultipleSalonsToDatabase()
        {
            //Arrange
            Salon firstTestSalon = new Salon("British Hairways", "a great salon");

            firstTestSalon.Save();
            Salon secondTestSalon = new Salon("The Second Combing", "a wonderful salon");

            secondTestSalon.Save();
            //Act
            List <Salon> result         = Salon.GetAll();
            List <Salon> expectedResult = new List <Salon> {
                firstTestSalon, secondTestSalon
            };

            //Assert
            Assert.Equal(result, expectedResult);
        }
Esempio n. 12
0
        public void Test_GetStylists_ReturnsTrueIfListsAreTheSame()
        {
            //Arrange
            Salon newSalon = new Salon("British Hairways", "a great salon");

            newSalon.Save();
            Stylist firstTestStylist = new Stylist("Harry Cutter", "a great stylist", newSalon.GetId());

            firstTestStylist.Save();
            Stylist secondTestStylist = new Stylist("Dwayne Johnson", "a wonderful stylist", newSalon.GetId());

            secondTestStylist.Save();
            Stylist thirdTestStylist = new Stylist("Jason Statham", "a marvelous stylist", newSalon.GetId());

            thirdTestStylist.Save();
            List <Stylist> expectedList = Stylist.GetAll();
            //Act
            List <Stylist> resultList = newSalon.GetStylists();

            //Arrange
            Assert.Equal(resultList, expectedList);
        }
Esempio n. 13
0
        public void Test_Delete_ReturnsTrueIfListsAreTheSame()
        {
            //Arrange
            Salon firstTestSalon = new Salon("British Hairways", "a great salon");

            firstTestSalon.Save();
            Salon secondTestSalon = new Salon("The Second Combing", "a wonderful salon");

            secondTestSalon.Save();
            Salon thirdTestSalon = new Salon("Sherlock Combs", "a marvelous salon");

            thirdTestSalon.Save();
            List <Salon> expectedList = new List <Salon> {
                firstTestSalon, secondTestSalon
            };

            //Act
            thirdTestSalon.Delete();
            List <Salon> resultList = Salon.GetAll();

            //Assert
            Assert.Equal(resultList, expectedList);
        }
Esempio n. 14
0
        public static Salon Find(int id)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand   cmd = new SqlCommand("SELECT * FROM salons WHERE id = @SalonId;", conn);
            SqlParameter salonIdParameter = new SqlParameter();

            salonIdParameter.ParameterName = "@SalonId";
            salonIdParameter.Value         = id.ToString();
            cmd.Parameters.Add(salonIdParameter);
            SqlDataReader rdr = cmd.ExecuteReader();

            int    foundSalonId    = 0;
            string foundSalonName  = null;
            string foundSalonAbout = null;

            while (rdr.Read())
            {
                foundSalonId    = rdr.GetInt32(0);
                foundSalonName  = rdr.GetString(1);
                foundSalonAbout = rdr.GetString(2);
            }
            Salon foundSalon = new Salon(foundSalonName, foundSalonAbout, foundSalonId);

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
            return(foundSalon);
        }
Esempio n. 15
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            }; //homepage

            Get["/salons"] = _ => {
                List <Salon> allSalons = Salon.GetAll();
                return(View["salons.cshtml", allSalons]);
            }; //list of all salons

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

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

            Get["/salons/new"] = _ => {
                return(View["add_salon.cshtml"]);
            }; //navigates to form to add new salon

            Post["/salons/new"] = _ => {
                Salon newSalon = new Salon(Request.Form["salon-name"], Request.Form["salon-about"]);
                newSalon.Save();
                List <Salon> allSalons = Salon.GetAll();
                return(View["salons.cshtml", allSalons]);
            }; //posts from form adding new salon, returns list of all salons

            Get["/stylists/new"] = _ => {
                List <Salon> AllSalons = Salon.GetAll();
                return(View["add_stylist.cshtml", AllSalons]);
            }; //navigates to form to add new stylist

            Post["/stylists/new"] = _ => {
                Stylist newStylist = new Stylist(Request.Form["stylist-name"], Request.Form["stylist-bio"], Request.Form["salon-id"]);
                newStylist.Save();
                List <Stylist> allStylists = Stylist.GetAll();
                return(View["stylists.cshtml", allStylists]);
            }; //posts from form adding new stylist, returns list of all stylists

            Get["/clients/new"] = _ => {
                List <Stylist> AllStylists = Stylist.GetAll();
                return(View["add_client.cshtml", AllStylists]);
            }; //navigates to form to add new client

            Post["/clients/new"] = _ => {
                Client newClient = new Client(Request.Form["client-name"], Request.Form["stylist-id"]);
                newClient.Save();
                List <Client> allClients = Client.GetAll();
                return(View["clients.cshtml", allClients]);
            }; //posts from form adding new client, returns list of all clients

            Get["/salons/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Salon          SelectedSalon      = Salon.Find(parameters.id);
                List <Stylist> SalonStylists      = SelectedSalon.GetStylists();
                model.Add("salon", SelectedSalon);
                model.Add("stylists", SalonStylists);
                return(View["salon.cshtml", model]);
            }; //retrieves individual salon pages

            Get["/salon/{id}/edit"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Salon  SelectedSalon = Salon.Find(parameters.id);
                string salonEdit     = Request.Query["salon-edit"];
                model.Add("form-type", salonEdit);
                model.Add("salon", SelectedSalon);
                return(View["edit.cshtml", model]);
            }; //edit individual salon

            Patch["/salon/{id}/edit"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Salon SelectedSalon = Salon.Find(parameters.id);
                SelectedSalon.Update(Request.Form["salon-name"], Request.Form["salon-about"]);
                List <Stylist> SalonStylists = SelectedSalon.GetStylists();
                model.Add("salon", SelectedSalon);
                model.Add("stylists", SalonStylists);
                return(View["salon.cshtml", model]);
            }; //returns edited salon page

            Get["salon/{id}/delete"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Salon  SelectedSalon = Salon.Find(parameters.id);
                string salonDelete   = Request.Query["salon-delete"];
                model.Add("form-type", salonDelete);
                model.Add("salon", SelectedSalon);
                return(View["delete.cshtml", model]);
            }; //delete individual salon

            Delete["salon/{id}/delete"] = parameters => {
                Salon SelectedSalon = Salon.Find(parameters.id);
                SelectedSalon.Delete();
                List <Salon> allSalons = Salon.GetAll();
                return(View["salons.cshtml", allSalons]);
            }; //returns confirmation of deleted salon

            Get["/stylists/{id}"] = parameters => {
                Stylist       SelectedStylist     = Stylist.Find(parameters.id);
                List <Client> stylistClients      = SelectedStylist.GetClients();
                Dictionary <string, object> model = new Dictionary <string, object>();
                model.Add("stylist", SelectedStylist);
                model.Add("clients", stylistClients);
                return(View["stylist.cshtml", model]);
            }; //retrieves individual stylist pages

            Get["/stylist/{id}/edit"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Stylist SelectedStylist           = Stylist.Find(parameters.id);
                string  stylistEdit = Request.Query["stylist-edit"];
                model.Add("form-type", stylistEdit);
                model.Add("stylist", SelectedStylist);
                return(View["edit.cshtml", model]);
            }; //edit individual stylist

            Patch["/stylist/{id}/edit"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Stylist SelectedStylist           = Stylist.Find(parameters.id);
                SelectedStylist.Update(Request.Form["stylist-name"], Request.Form["stylist-bio"]);
                List <Client> StylistClients = SelectedStylist.GetClients();
                model.Add("stylist", SelectedStylist);
                model.Add("clients", StylistClients);
                return(View["stylist.cshtml", model]);
            }; //returns edited stylist page

            Get["stylist/{id}/delete"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Stylist SelectedStylist           = Stylist.Find(parameters.id);
                string  stylistDelete             = Request.Query["stylist-delete"];
                model.Add("form-type", stylistDelete);
                model.Add("stylist", SelectedStylist);
                return(View["delete.cshtml", model]);
            }; //delete individual stylist

            Delete["stylist/{id}/delete"] = parameters => {
                Stylist SelectedStylist = Stylist.Find(parameters.id);
                SelectedStylist.Delete();
                List <Stylist> allStylists = Stylist.GetAll();
                return(View["stylists.cshtml", allStylists]);
            }; //returns confirmation of deleted stylist

            Get["/clients/{id}"] = parameters => {
                Client SelectedClient             = Client.Find(parameters.id);
                Dictionary <string, object> model = new Dictionary <string, object>();
                model.Add("client", SelectedClient);
                return(View["client.cshtml", model]);
            }; //retrieves individual client pages

            Get["/client/{id}/edit"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Client SelectedClient             = Client.Find(parameters.id);
                string clientEdit = Request.Query["client-edit"];
                model.Add("form-type", clientEdit);
                model.Add("client", SelectedClient);
                return(View["edit.cshtml", model]);
            }; //edit individual client

            Patch["/client/{id}/edit"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Client SelectedClient             = Client.Find(parameters.id);
                SelectedClient.UpdateString(Request.Form["client-name"]);
                model.Add("client", SelectedClient);
                return(View["client.cshtml", model]);
            }; //returns edited client page

            Get["client/{id}/delete"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Client SelectedClient             = Client.Find(parameters.id);
                string clientDelete = Request.Query["client-delete"];
                model.Add("form-type", clientDelete);
                model.Add("client", SelectedClient);
                return(View["delete.cshtml", model]);
            }; //delete individual client

            Delete["client/{id}/delete"] = parameters => {
                Client SelectedClient = Client.Find(parameters.id);
                SelectedClient.Delete();
                List <Client> allClients = Client.GetAll();
                return(View["clients.cshtml", allClients]);
            }; //returns confirmation of deleted client
        }
Esempio n. 16
0
 public void Dispose()
 {
     Salon.DeleteAll();
     Stylist.DeleteAll();
 }