public void AddRequestSetting(Hashtable hashtable) { using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB"))) { string sql = "INSERT INTO REQUEST_TYPE_REQUEST_THEME VALUES" + "(@TypeId, @ThemeId, @Description, @NormExecutionTimeInSeconds, @NormExecutionTimeReadable)"; var exception = false; try { connection.Execute(sql, new { TypeId = hashtable["requestType"], ThemeId = hashtable["requestTheme"], Description = hashtable["description"], NormExecutionTimeInSeconds = hashtable["normExecutionTimeInSeconds"], NormExecutionTimeReadable = hashtable["normExecutionTimeReadable"] }); } catch (SqlException ex) { exception = true; if (ex.Message.Contains("UQ_REQUEST_TYPE_REQUEST_THEME")) { RequestSettingExistException?.Invoke(this, null); } } if (!exception) { SuccessRecordInsert?.Invoke(this, null); } } }
public void AddRequest(Hashtable hashtable) { using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB"))) { string sql = "INSERT INTO REQUEST(RequestTypeRequestThemeId, ShortDescription, FullDescription, CreatedAt, CreatedByEmployeeId) " + "VALUES ( @RequestTypeRequestThemeId, @ShortDescription, @FullDescription, GETUTCDATE(), @CreatedByEmployeeId )"; var exception = false; try { connection.Execute(sql, new { RequestTypeRequestThemeId = hashtable["requestTypeRequestThemeId"], ShortDescription = hashtable["shortDescription"], FullDescription = hashtable["fullDescription"], CreatedByEmployeeId = hashtable["createdByEmployeeId"] }); } catch (Exception) { exception = true; } if (exception) { UndefinedException?.Invoke(this, null); } else { SuccessRecordInsert?.Invoke(this, null); } } }
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); } } }
public void SimpleInsert(string tableName, string value) { using (IDbConnection connection = new SqlConnection(Helper.GetConnectionString("UserSupportDB"))) { string sql = $"INSERT INTO {tableName} VALUES(@Value)"; var exception = false; try { connection.Execute(sql, new { Value = value }); } 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) { SuccessRecordInsert?.Invoke(this, null); } } }