Example #1
0
 public void AddEmployee(Dictionary <string, string> txtBoxes,
                         Dictionary <string, int> cmbBoxes,
                         Dictionary <string, bool> chkBoxes)
 {
     using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB")))
     {
         string sql = "INSERT INTO EMPLOYEE(PositionId, DepartmentId, RoleId, UserName, Password, FirstName, " +
                      "LastName, SurName, RoomNumber, Address, Email, PhoneNumber, WorkingState) VALUES " +
                      "(@PositionId, @DepartmentId, @RoleId, @UserName, @Password, @FirstName, @LastName, " +
                      "@SurName, @RoomNumber, @Address, @Email, @PhoneNumber, @WorkingState)";
         var exception = false;
         try
         {
             connection.Execute(sql, new
             {
                 PositionId   = cmbBoxes["positionsCmbBox"],
                 DepartmentId = cmbBoxes["departmentsCmbBox"],
                 RoleId       = cmbBoxes["rolesCmbBox"],
                 UserName     = txtBoxes["userNameTxtBox"],
                 Password     = txtBoxes["passwordTxtBox"],
                 FirstName    = txtBoxes["firstNameTxtBox"],
                 LastName     = txtBoxes["lastNameTxtBox"],
                 SurName      = txtBoxes["surNameTxtBox"],
                 RoomNumber   = txtBoxes["roomNumberTxtBox"],
                 Address      = txtBoxes["addressTxtBox"],
                 Email        = txtBoxes["emailTxtBox"],
                 PhoneNumber  = txtBoxes["phoneNumberTxtBox"],
                 WorkingState = chkBoxes["workingStateChkBox"]
             });
         }
         catch (SqlException ex)
         {
             exception = true;
             if (ex.Message.Contains("UserName"))
             {
                 UserNameExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("Email"))
             {
                 EmailExistException?.Invoke(this, null);
             }
             else
             {
                 DBConnectionException?.Invoke(this, null);
             }
         }
         if (!exception)
         {
             SuccessRecordInsert?.Invoke(this, null);
         }
     }
 }
Example #2
0
 public void UpdateEmployee(Dictionary <string, string> txtBoxes,
                            Dictionary <string, int> cmbBoxes,
                            Dictionary <string, bool> chkBoxes,
                            int employeeId)
 {
     using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB")))
     {
         string sql = "UPDATE EMPLOYEE " +
                      "SET  PositionId = @PositionId, " +
                      "DepartmentId = @DepartmentId, " +
                      "RoleId = @RoleId, " +
                      "UserName = @UserName, " +
                      "Password = @Password, " +
                      "FirstName = @FirstName, " +
                      "LastName = @LastName, " +
                      "SurName = @SurName, " +
                      "RoomNumber = @RoomNumber, " +
                      "Address = @Address, " +
                      "Email = @Email, " +
                      "PhoneNumber = @PhoneNumber, " +
                      "WorkingState = @WorkingState " +
                      "WHERE Id = @Id";
         var exception = false;
         try
         {
             connection.Execute(sql, new
             {
                 PositionId   = cmbBoxes["positionsCmbBox"],
                 DepartmentId = cmbBoxes["departmentsCmbBox"],
                 RoleId       = cmbBoxes["rolesCmbBox"],
                 UserName     = txtBoxes["userNameTxtBox"],
                 Password     = txtBoxes["passwordTxtBox"],
                 FirstName    = txtBoxes["firstNameTxtBox"],
                 LastName     = txtBoxes["lastNameTxtBox"],
                 SurName      = txtBoxes["surNameTxtBox"],
                 RoomNumber   = txtBoxes["roomNumberTxtBox"],
                 Address      = txtBoxes["addressTxtBox"],
                 Email        = txtBoxes["emailTxtBox"],
                 PhoneNumber  = txtBoxes["phoneNumberTxtBox"],
                 WorkingState = chkBoxes["workingStateChkBox"],
                 Id           = employeeId
             });
         }
         catch (SqlException ex)
         {
             exception = true;
             if (ex.Message.Contains("UserName"))
             {
                 UserNameExistException?.Invoke(this, null);
             }
             else if (ex.Message.Contains("Email"))
             {
                 EmailExistException?.Invoke(this, null);
             }
         }
         if (!exception)
         {
             SuccessRecordUpdate?.Invoke(this, null);
         }
     }
 }