public OperationResult UpdateCopier(Copier copier) { OperationResult operationResult = new OperationResult(); using (IDbConnection db = new SqlConnection(ConfigurationValues.DeskTopConnection)) { try { const string query = "UPDATE [Scanners]" + " SET DeviceName = @DeviceName" + ", SerialNumber = @SerialNumber" + " WHERE ID = @ID"; int rowsAffectd = db.Execute(query, new { @DeviceName = copier.DeviceName, @SerialNumber = copier.SerialNumber, @ID = copier.ID }); operationResult.Success = true; operationResult.ErrorMessage = "None"; return operationResult; } catch (Exception er) { operationResult.Success = true; operationResult.ErrorMessage = er.ToString(); return operationResult; } } }
public OperationResult AddCopier(Copier copier) { OperationResult operationResult = new OperationResult(); using (IDbConnection db = new SqlConnection(ConfigurationValues.DeskTopConnection)) { try { const string query = "INSERT INTO [Scanners]" + " (" + " [DeviceName],[SerialNumber]" + ")" + "VALUES" + "(" + " @DeviceName,@SerialNumber" + ")"; int rowsAffectd = db.Execute(query, new { @DeviceName = copier.DeviceName, @SerialNumber = copier.SerialNumber, }); operationResult.Success = true; operationResult.ErrorMessage = "None"; return operationResult; } catch (Exception er) { operationResult.Success = true; operationResult.ErrorMessage = er.ToString(); return operationResult; } } }
public OperationResult DeleteCopier(Copier copier) { OperationResult operationResult = new OperationResult(); using (IDbConnection db = new SqlConnection(ConfigurationValues.DeskTopConnection)) { try { const string query = "delete from [Scanners]" + " where id = @id"; int rowsAffectd = db.Execute(query, new { @id = copier.ID }); operationResult.Success = true; operationResult.ErrorMessage = "None"; return operationResult; } catch (Exception er) { operationResult.Success = true; operationResult.ErrorMessage = er.ToString(); return operationResult; } } }