public void UpdateRequestSetting(Hashtable hashtable) { using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB"))) { string sql = "UPDATE REQUEST_TYPE_REQUEST_THEME SET " + "RequestTypeId = @TypeId, " + "RequestThemeId = @ThemeId, " + "Description = @Description, " + "NormExecutionTimeInSeconds = @NormExecutionTimeInSeconds, " + "NormExecutionTimeReadable = @NormExecutionTimeReadable " + "WHERE Id = @Id"; var exception = false; try { connection.Execute(sql, new { TypeId = hashtable["requestType"], ThemeId = hashtable["requestTheme"], Description = hashtable["description"], NormExecutionTimeInSeconds = hashtable["normExecutionTimeInSeconds"], NormExecutionTimeReadable = hashtable["normExecutionTimeReadable"], Id = hashtable["id"] }); } catch (SqlException ex) { exception = true; if (ex.Message.Contains("UQ_REQUEST_TYPE_REQUEST_THEME")) { RequestSettingExistException?.Invoke(this, null); } } if (!exception) { SuccessRecordUpdate?.Invoke(this, null); } } }
public void SimpleUpdate(string tableName, string columnName, string value, int id) { using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB"))) { string sql = $"UPDATE {tableName} SET {columnName} = @Value WHERE Id = @Id"; var exception = false; try { connection.Execute(sql, new { Value = value, Id = id }); } catch (SqlException ex) { exception = true; if (ex.Message.Contains("UQ_POSITION_PositionName")) { PositionExistException?.Invoke(this, null); } else if (ex.Message.Contains("UQ_DEPARTMENT_DepartmentName")) { DepartmentExistException?.Invoke(this, null); } else if (ex.Message.Contains("UQ_REQUEST_THEME_ThemeName")) { RequestThemeExistException?.Invoke(this, null); } else if (ex.Message.Contains("UQ_REQUEST_TYPE_TypeName")) { RequestTypeExistException?.Invoke(this, null); } } if (!exception) { SuccessRecordUpdate?.Invoke(this, null); } } }
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); } } }