コード例 #1
0
ファイル: ClientTest.cs プロジェクト: yichiang/Hair-Salon
        public void Test2_Return_ClientObjectsOverride()
        {
            Client firstClient = new Client("dsds",13);
             Client secondClient = new Client("dsds",13);

             Assert.Equal(firstClient, secondClient);
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: yichiang/Hair-Salon
        public static Client Find(int Id)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

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

              string foundName=null;
              int foundStylistId=0;
              int foundId=0;

              while(rdr.Read())
              {
            foundId=rdr.GetInt32(0);
            foundName=rdr.GetString(1);
            foundStylistId=rdr.GetInt32(2);
              }
              Client foundClient= new Client(foundName, foundStylistId, foundId);

              if (rdr!= null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundClient;
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: RubyBe/Salon
 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;
       string foundClientTreatment = null;
       while(rdr.Read())
       {
     foundClientId = rdr.GetInt32(0);
     foundClientName = rdr.GetString(1);
     foundClientTreatment = rdr.GetString(1);
       }
       Client foundClient = new Client(foundClientName, foundClientTreatment, foundClientId);
       if(rdr!=null)
       {
     rdr.Close();
       }
       if(conn!=null)
       {
     conn.Close();
       }
       return foundClient;
 }
コード例 #4
0
ファイル: ClientTest.cs プロジェクト: RubyBe/Salon
 public void Test_NamesAreEqual_ReturnsTrueIfNamesAreTheSame()
 {
     // Arrange, Act
       Client firstClient = new Client("Doc Gonzo", "Brush", 1);
       Client secondClient = new Client("Doc Gonzo", "Brush", 1);
       //Assert
       Assert.Equal(firstClient, secondClient);
 }
コード例 #5
0
ファイル: ClientTest.cs プロジェクト: yichiang/Hair-Salon
        public void Test4_Save_AssignsIdToObjects()
        {
            Client firstClient = new Client("erere", 13);
              firstClient.Save();
              Client savedClient = Client.GetAll()[0];

              Assert.Equal(firstClient, savedClient);
        }
コード例 #6
0
ファイル: ClientTest.cs プロジェクト: yichiang/Hair-Salon
        public void Test6_Update_ClientInDatabase()
        {
            Client oneClient = new Client("erere", 13);
              oneClient.Save();
              oneClient.Update("q");
              string result = oneClient.GetName();

              Assert.Equal("q", result);
        }
コード例 #7
0
ファイル: ClientTest.cs プロジェクト: yichiang/Hair-Salon
        public void Test3_Save_ClientsToObjects()
        {
            List<Client> saveOneClient = new List<Client>{};
              Client firstClient = new Client("erere", 13);
              saveOneClient.Add(firstClient);
              firstClient.Save();
              List<Client> allClients=Client.GetAll();

              Assert.Equal(saveOneClient,allClients);
        }
コード例 #8
0
ファイル: ClientTest.cs プロジェクト: RubyBe/Salon
 public void FindById_FindsAClientById_ClientFoundById()
 {
     // Arrange
       Client testClient = new Client("Doc Gonzo", "Brush", 1);
       testClient.Save();
       // Act
       Client foundClient = Client.Find(testClient.GetId());
       // Assert
       Assert.Equal(testClient, foundClient);
 }
コード例 #9
0
ファイル: HomeModule.cs プロジェクト: RubyBe/Salon
        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"];
             };
        }
コード例 #10
0
ファイル: ClientTest.cs プロジェクト: yichiang/Hair-Salon
        public void Test5_Find_FindsClientInDatabase()
        {
            //Arrange
               Client oneClient = new Client("erere", 13);
               oneClient.Save();

               //Act
               Client foundClient  = Client.Find(oneClient.GetId());
               //Assert
               Assert.Equal(oneClient, foundClient);
        }
コード例 #11
0
ファイル: ClientTest.cs プロジェクト: RubyBe/Salon
 public void Test_Save_AssignsIdToObject()
 {
     // Arrange
       Client testClient = new Client("Doc Gonzo", "Haircut", 1);
       // Act
       testClient.Save();
       Client savedClient = Client.GetAll()[0];
       int result = savedClient.GetId();
       int testId = testClient.GetId();
       // Assert
       Assert.Equal(testId, result);
 }
コード例 #12
0
ファイル: StylistsTest.cs プロジェクト: yichiang/Hair-Salon
        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);
        }
コード例 #13
0
ファイル: ClientTest.cs プロジェクト: RubyBe/Salon
 public void Test_Delete_DeletesClientFromDatabase()
 {
     // Arrange
       string name = "Yousef";
       Client testClient = new Client(name, "Cuts", 1);
       testClient.Save();
       string name2 = "John";
       Client testClient2 = new Client(name, "Brushes", 1);
       testClient2.Save();
       // Act
       testClient.Delete();
       List<Client> resultClients = Client.GetAll();
       List<Client> testClientList = new List<Client> {testClient2};
       // Assert
       Assert.Equal(testClientList, resultClients);
 }
コード例 #14
0
ファイル: StylistTest.cs プロジェクト: RubyBe/Salon
 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);
 }
コード例 #15
0
ファイル: ClientTest.cs プロジェクト: yichiang/Hair-Salon
        public void Test7_DeleteOneClient_true()
        {
            Client firstClientsClient = new Client("erere",87);
             firstClientsClient.Save();

             Client secondClientsDsih= new Client("erere",56);
             secondClientsDsih.Save();

             firstClientsClient.Delete();

             List<Client> resultClient=Client.GetAll();
             List<Client> afterDeleteOneClientsClient= new List<Client> {secondClientsDsih};

             Assert.Equal(afterDeleteOneClientsClient,resultClient);
        }
コード例 #16
0
 public void Dispose()
 {
     Stylist.DeleteAll();
     Client.DeleteAll();
 }
コード例 #17
0
ファイル: Stylists.cs プロジェクト: yichiang/Hair-Salon
        public List<Client> GetClient()
        {
            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> allClientes = new List<Client> {};
              while(rdr.Read())
              {
            int dishId = rdr.GetInt32(0);
            string dishName = rdr.GetString(1);
            int dishStylistId = rdr.GetInt32(2);

            Client newClient = new Client(dishName,dishStylistId,dishId);
            allClientes.Add(newClient);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allClientes;
        }
コード例 #18
0
ファイル: ClientTest.cs プロジェクト: RubyBe/Salon
 public void Update_UpdatesAClient_ClientUpdated()
 {
     // Arrange
       string name1 = "Doc Gonzo";
       string service1 = "Fur";
       Client testClient1 = new Client(name1, service1, 1);
       testClient1.Save();
       string name2 = "Doctor Gonzo";
       string nameExpected = name2;
       // Act
       testClient1.Update(name2);
       string nameResult = testClient1.GetName();
       // Assert
       Assert.Equal(nameExpected, nameResult);
 }
コード例 #19
0
ファイル: StylistsTest.cs プロジェクト: yichiang/Hair-Salon
        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);
        }
コード例 #20
0
ファイル: Stylist.cs プロジェクト: RubyBe/Salon
        // a method to get a stylist's list of clients
        public List<Client> GetClients(int id)
        {
            List<Client> allClients = new List<Client>{};
              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 = id.ToString();
              cmd.Parameters.Add(stylistIdParameter);

              SqlDataReader rdr = cmd.ExecuteReader();

              int foundClientId = 0;
              string foundClientName = null;
              string foundClientTreatment = null;
              while(rdr.Read())
              {
            foundClientId = rdr.GetInt32(0);
            foundClientName = rdr.GetString(1);
            foundClientTreatment = rdr.GetString(2);
            Client foundClient = new Client(foundClientName, foundClientTreatment, foundClientId);
            allClients.Add(foundClient);
              }
              if(rdr!=null)
              {
            rdr.Close();
              }
              if(conn!=null)
              {
            conn.Close();
              }
              return allClients;
        }
コード例 #21
0
ファイル: HomeModules.cs プロジェクト: yichiang/Hair-Salon
        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];

            };
        }
コード例 #22
0
ファイル: Client.cs プロジェクト: yichiang/Hair-Salon
        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();

              int id=0;
              string name= null;
              int stylistId=0;
              while(rdr.Read())
              {
              id=rdr.GetInt32(0);
              name= rdr.GetString(1);
              stylistId=rdr.GetInt32(2);
              Client newClient= new Client(name,stylistId,id);
              allClients.Add(newClient);
              }

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

              return allClients;
        }
コード例 #23
0
ファイル: ClientTest.cs プロジェクト: RubyBe/Salon
 public void Test_Save_SavesToDatabase()
 {
     // Arrange
       Client testClient = new Client("Doc Gonzo", "Brush", 1);
       testClient.Save();
       // Act
       List<Client> listResult = Client.GetAll();
       List<Client> listExpected = new List<Client>{testClient};
       // Assert
       Assert.Equal(listExpected, listResult);
 }